What will be the output of the following C++ code? [code] #include <iostream> #include <string> using namespace std;

Hằng Đoàn

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str;
        string str2="Steve jobs";
        string str3="He founded apple";
        str.append(str2);
        str.append(str3, 6, 3);
        str.append(str3.begin() + 6, str3.end());
        str.append(5,0x2e);
        cout << str << '\n';
        return 0;
    }
A. Steve jobs
B. He founded apple
C. Steve
D. Steve jobsndended apple.....
 
Answer: d
Explanation: In this program, We are adding characters to the string, So the output will as follows after addition of characters.
Output:
Code:
$ g++ str.cpp
$ a.out
Steve jobsndended apple.....
 

Tìm kiếm

Back
Top