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

What will be the output of the following C++ code?
Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        string str ("steve jobs is legend");
        string::iterator it;
        str.erase (str.begin()+ 5, str.end()-7);
        cout << str << endl;      
        return 0;
    }
A. jobs is
B. steve legend
C. steve
D. steve jobs is
 
Answer: b
Explanation: In this program, We are leaving the first 5 characters and last 7 characters and we are erasing the remaining the characters.
Output:
Code:
$ g++ stri3.cpp
$ a.out
steve legend
 

Tìm kiếm

Back
Top