C++从纯文本中读取字符串(string)内容
void demo::fr()
{
// read string from text file
ifstream fin;
fin.open("sample.in");
ifstream fin_result;
fin_result.open("sample.out");
string line;
string line_result;
int no=0;
if(NULL!=getline(fin,line))
{
cout<<"line no="< }
while(getline(fin,line)&&getline(fin_result,line_result))
{
cout<<"no"< line_result = line_result.substr(9); // read the content from the 9 position
cout<<"no"< }
string ss("god!"); // show the length of string ss
cout<<"no="< fin.close();
fin_result.close();
}