Loading... ## 演示代码如下 ```cpp #include<iostream> #include<fstream> #include<string> using namespace std; int main() { // 栈中数据写文件 ofstream f; f.open("C:\\data.txt", ios::out|ios::app); f << "1314 mysql数据库 本当迷 北京大学 2002/6/22 10 199 200" << endl; f.close(); string str; // 从文件读取数据 ifstream infile; infile.open("C:\\data.txt", ios::in); string name; string num; string author, publisher, qtyOnhand, who, ret, m; while(infile>>name>>num>>author>>publisher>>qtyOnhand>>who>>ret>>m){ cout << name << " " << num << " "<<author << " "<< publisher<<" "<<qtyOnhand << " " << who << " " << ret << " "<< m<< endl; } infile.close(); cout << "hello world" << endl; return 0; } ``` ## 说明: 我们改变文件的地址就可以使用了 最后修改:2022 年 06 月 28 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果文章有用,请随意打赏。