#include <iostream>
#include <string>
String myname;
Getline (CIN, myname);
cout<<myname<<endl;
Reprint: http://blog.csdn.net/slience_perseverance/article/details/19819601
Getline (IStream &in, String &s)
Reads a line from the input stream to string s
• Function: – Read the character from the input stream, and save it to a string variable – until the following occurs: • Read the end of file sign • Read a new line • Reach the maximum length of a string-if Getline does not read the character, it returns false and can be used to determine whether the file ends[CPP] View Plain copy print? #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string buff; ifstream infile; ofstream outfile; cout<< "Input file name: "<<endl; cin>>buff; infile.open (Buff.c_str ()); if (!infile) cout<< "Error" <<buff<<endl; cout<< "input outfile name: " < <endl; cin>>buff; outfile.open (Buff.c_str ()); while (Getline (Infile, buff)) outfile<<buff <<endl; infile.close (); outfile.close (); return 0; }