Mega Code Archive

 
Categories / C++ / String
 

STL string Instantiation and Copy Techniques

#include <string> #include <iostream> using namespace std; int main () {    const char* pChar = "Hello String!";    cout << pChar << endl;    std::string strFromConst (pChar);    cout << strFromConst << endl;    std::string str2 ("Hello String!");    std::string str2Copy (str2);    cout << str2Copy << endl;    // Initialize a string to the first 5 characters of another    std::string subString (pChar, 5);    cout << subString << endl;    return 0; }