如何打开vector容器的文件

lty369963 lty369963 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是《c++primer练习》8.8的一道练习题
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
using namespace std;
void process(string);

int main()
{
vector<string> files;
string filename, s;
while (cin>>filename)
files.push_back(filename);
ifstream input;
vector<string>::const_iterator it=files.begin();
while(it!=files.end()){
input.open(it->c_str());
if(!input)
{
cerr<<"error can not open file:"<<*it<<endl; ++it;
}//if
else
{
//若打开成功,则读入并处理文件流input
while(input>>s)//处理文件
process(s);
input.close();//关闭文件
input.clear(); ++it;
}//else
}//while
return 0;
}
void process(string s)
{
cout<<s;
}
我输入字符串 都是出现error can not open file:“输入的字符串”
我想问的是:vcetor中的文件时什么?在哪?是不是一定要有这个文件才能打开?
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
lty369963
C++ 语言 65,214 成员 250,514 内容