【发布时间】:2016-03-25 01:40:45
【问题描述】:
长话短说,我需要将向量作为单行进行计算,而无需创建自己的新行以使我的程序正常工作。我读入向量的文本文件是
laptop#a small computer that fits on your lap#
helmet#protective gear for your head#
couch#what I am sitting on#
cigarette#smoke these for nicotine#
binary#ones and zeros#
motorcycle#two wheeled motorized bike#
oj#orange juice#
test#this is a test#
使用循环填充向量:
if(myFile.is_open())
{
while(getline(myFile, line, '#'))
{
wordVec.push_back(line);
}
cout << "words added.\n";
}
并用这个打印出来:
for(int i = 0; i < wordVec.size(); i++)
{
cout << wordVec[i];
}
它的输出如下:
laptopa small computer that fits on your lap
helmetprotective gear for your head
couchwhat I am sitting on
cigarettesmoke these for nicotine
binaryones and zeros
motorcycletwo wheeled motorized bike
ojorange juice
testthis is a test
如果我手动输入单词并将它们添加到我的数据结构中,我的程序可以工作,但是如果从通过文本文件填充的向量中添加,则一半的程序不起作用。在有人说要求更好地描述问题之前,我只需要知道如何填充向量,以便它将作为单行输出。
【问题讨论】: