[英]read string with whitespaces from file
因此,基本上,我正在制作一個簡單的程序,該程序從文件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
應該是一個字符串,我該怎么做?
更改
fd >> pavadinimas; // ">>" will stop parsing when hitting spaces
至
getline(fd, pavadinimas); // will parse the whole line
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.