【发布时间】:2014-05-22 15:27:49
【问题描述】:
在我现在正在处理的代码中,我从 txt 文件中加载了一个向量,现在我试图查看它们是否是一种在不需要位置或任何东西的情况下替换向量中某些单词的方法
因此,例如,如果 txt 包含动物列表并且我想将鸟更改为预订,我将如何做到这一点而不需要字母的位置
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
vector <string> test;
int main()
{
string file;
fstream fout( "Vector.txt" );
while ( !fout.eof())
{
getline(fout,file);
test.push_back(file);
}
fout.close();
for( int i = 0; i < test.size(); i++)
{
cout << test[i] << endl;
}
system("pause");
}
txt 包含:
狗
猫
鸟
河马
狼
【问题讨论】:
-
不清楚你在 test[i] 中有什么(一个词,一个句子?)。
-
你能发布一个输入 txt 示例和一个可能的输出吗?我不明白你想做什么。
-
好吧,基本上不用知道我想将txt文件中的单词更改为其他内容的位置