Strings
- How many parameters can a resize method take?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
There can be one or two parameters in resize method. They are string length and an optional new character to be inserted.
- What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s1;
string s2="Manjesh Ojha";
string s3="He founded Interview Mania";
s1.append(s2);
s1.append(s3, 2, 4);
s1.append(s3.begin() + 6, s3.end());
s1.append(5, 0x2E);
cout << s1 << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are characters to the string, So the output will as follows.
- What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Testing str...");
for ( string :: iterator Iter = str.begin(); Iter != 5; ++Iter)
cout << *Iter;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In the for loop, We are not allowed to give a numeric value in string, So it is arising an error.
- What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string name ("Manjesh");
string family ("Ojha");
name += " Interview Mania ";
name += family;
name += '\n';
cout << name;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are adding the characters at the end of the current value.
- What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string s="Manjesh Ojha founded the Interview Mania";
string s2 = s.substr (0, 12);
unsigned pos = s.find("the");
string s3 = s.substr (pos);
cout << s2 << ' ' << s3 << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are finding the substring of the string by using the substr function.