【发布时间】:2015-02-26 21:11:42
【问题描述】:
int i = 5;
char c = 'n';
string st = "cool";
ofstream my("we.txt");
my <<st<<","<<c<<","<<i<<","<<endl;
string s;
ifstream your("we.txt");
while(your){
getline(your, st, ',');
your>>c;
your.ignore(1);
your>>i;
your.ignore(1);
cout<<st<<","<<c<<","<<i<<endl;
}
my.close();
我什至不知道 your.ignore(1) 代表什么,但它以某种方式起作用。问题是它打印了两次结果,为什么? 有人可以解释我如何处理我写在文件中的信息吗?如果我想在文件中保存 3 信息字符串交易、双倍价格和已售出的字符 (y/n),关于我拥有的每件商品,我该如何管理它? 它看起来像这样 天伯伦, 40, n; 古驰,10,是的; ……等等……
我现在需要它,因为明天我要考试,感谢您的帮助,对不起我的英语!
【问题讨论】:
-
This reference of
ignore可能会有所帮助。