- (10%)
Determine
whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// String Objects (P.405)
#include <iostream>
#include <string>
using std::string;
int main()
{
int m = 5;
string n(m, 'n');
std::cout << n << std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Modifying Strings (P.410)
#include
<iostream>
#include <string>
using std::string;
int main()
{
string a("Audrey Hepburn");
string b(a, 0, 6);
std::cout << b.replace(3,3,"i") << std::endl;
return 0;
}
- (10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
// Searching Strings (P.418)
#include <iostream>
#include <string>
using std::string;
int main()
{
string a("Audrey Hepburn");
string b("e");
std::cout << a.find(b) << a.find(b, 5) << std::endl;
// string::npos = 18446744073709551615, which is 2^64 - 1.
return 0;
}