我有了字符串,例如讀取一行同時C++
文件你好,我的名字是喬
你怎麼樣?
好嗎?
我試圖輸出該文件,但我的程序輸出爲「HellomynameisJoeHowAreyouDoing?Goodyou?」我遇到空間和新行的問題。
int main (int argc, char* argv[])
{
index_table table1;
string word;
ifstream fileo;
fileo.open(argv[1]); //where this is the name of the file that is opened
vector<string> line;
while (fileo >> word){
line.push_back(word);
}
cout << word_table << endl;
for (int i=0; i < line.size(); i++)
{
if (find(line.begin(), line.end(), "\n") !=line.end())
cout << "ERRROR\n"; //My attempt at getting rid of new lines. Not working though.
cout << line[i];
}
fileo.close();
return 0;
你可能想看看'std :: getline'。 – juanchopanza
使用'getline'方法 – Kunal