【发布时间】:2014-04-13 11:01:47
【问题描述】:
所以基本上,我正在制作一个简单的程序,它从文件 s 中获取名称,然后询问是否应该将它们写入另一个文件。
void ziureti(){
string pavadinimas, statymas, laimejo;
double kofas; //these are irrelevant to the problem
int suma; //these are irrelevant to the problem
cout << "Enter the name: ";
getline(cin, statymas);
ifstream fd (FV);
while (statymas != pavadinimas ){ //out here I iterate through the file until i find the neccesary name
fd >> pavadinimas;}
因此,当名称只有数字或字母时,它很好,但是当两者都存在时,程序找不到它们。有什么想法吗?
例如
Chelsea
10
1.8
Arsenal
15
2.3
Chelsea Arsenal
15
1.85
Chelsea Arsenal 应该是一个字符串,我该怎么做?
【问题讨论】:
-
你能举一个输入文件失败的例子吗?
-
好吧对不起,我弄乱了文件名和保存,但是当字符串中有空格时它仍然不起作用。我将如何解决这个问题? ` 切尔西 10 1.8 阿森纳 15 2.3 切尔西阿森纳(这应该是一串) 15 1.85 ` @celtschk
-
operator>>在空格处拆分。您可能还想在fd上使用getline。 -
@Marsietis 请编辑您的问题以添加更多信息。在 cmets 中它非常没用。