if(command=="insert")
{
int i=0;
while(i>=0)
{
string textToSave[i];
cout << "Enter the string you want saved: " << endl;
cin >>textToSave[i];
ofstream saveFile ("Save.txt");
saveFile << textToSave;
saveFile.close();
i++;
break;
}
}
我想将输入的数组存储到 .txt 文件中。但是我在创建要存储的数组时遇到问题。我也在whileloop和forloop之间纠结,但是觉得while循环更合适,因为不知道需要插入多少次单词。请帮忙。谢谢。
最佳答案
您正在尝试存储整个字符串数组,而不仅仅是当前字符串。不知道为什么你需要 i
并且有一个数组,因为无论如何你一次只是读写一个字符串。
它可能是这样的:
if(command=="insert")
{
string textToSave;
cout << "Enter the string you want saved: " << endl;
cin >>textToSave;
ofstream saveFile ("Save.txt");
saveFile << textToSave;
saveFile.close();
break;
}
关于c++ - 存储数组的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787885/