C++问题 IO 文件流 一直输出文件无法打开 10
#include<iostream>#include<stdexcept>#include<fstream>#include<vector>#include<string...
#include<iostream>
#include <stdexcept>
#include <fstream>
#include<vector>
#include <string>
using namespace std;
int main()
{
ifstream input;
vector<string> s;
string s1;
string word;
while(cin>>word)
s.push_back(word);
vector<string>::const_iterator it=s.begin();
while(it!=s.end())
{
input.open(it->c_str());
if(!input)
{
cout<<"文件无法打开"<<endl;
input.clear();
++it;
continue;
}
input>>s1;
cout<<s1;
input.close();
input.clear();
++it;
}
return 0;
} 展开
#include <stdexcept>
#include <fstream>
#include<vector>
#include <string>
using namespace std;
int main()
{
ifstream input;
vector<string> s;
string s1;
string word;
while(cin>>word)
s.push_back(word);
vector<string>::const_iterator it=s.begin();
while(it!=s.end())
{
input.open(it->c_str());
if(!input)
{
cout<<"文件无法打开"<<endl;
input.clear();
++it;
continue;
}
input>>s1;
cout<<s1;
input.close();
input.clear();
++it;
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询