istringstream iss;//char* buf[]="123 4.56 hello"
iss.str("123 4.56 hello");int i =0;double d =0.0;
string s;//sscanf(buf,"%d %lf %s",&i,&d,&s);
iss >> i >> d >> s;
cout << i << d << s <<endl;
ostringstream//sprinf()
ostringstream oss;int i =321;double d =4.56;
string s ="hello"//sprintf(buf,"%d %lf %s",i,d,s);
oss << i <<' '<< d <<' '<< s;
cout << oss.str()<< endl;
4. 文件流
头文件 #include <fstream>
ofstream //fprintf()
eg://写文件流
ofstream ofs("pathname",ios::out);//ios::out缺省参数可以不加,文件不存在会自动创建
ofs <<123<<' '<<4.56<<' '<<"abc"<< endl;
ofs.close();//关闭文件
ifstream //类似fscanf()
eg://读文件流
ifstream ifs("pathname");int i =0;double d =0.0;
string s;
ifs >> i >> d >> s;
cout << i <<","<< d<<","<< s << endl;
ifs.close();//关闭文件