//今天自己想把一个经过格式化后的字符串,写到文件中去,折腾了半天,用C/C++的方式都试了下,感觉C的比较方便,都差不多吧,把代码留下来方便以后回忆下
include
include
include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ostringstream os;
string name,gender;
string sname= “姓名: “;
string sgender=” 性别: “;
string sgrade=” 成绩: “;
double grade;
string tmp;
cin >> name >>gender >>grade;
os <<sname<< name <<sgender << gender << sgrade <<grade;
tmp=os.str();
cout << tmp << endl;
istringstream is(tmp);
is >> sname >>name >> sgender >>gender>>sgrade >>grade;
cout << sname <<name << endl;
cout << sgender <<gender << endl;
cout << sgrade <<grade << endl;
return 0;
}