64,654
社区成员
发帖
与我相关
我的任务
分享
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
istream& input(istream& in) {
string arr;
while (in >> arr, !in.eof()) {
if (in.fail()) {
cerr << "error:input error,please try again." << endl;
in.clear(istream::failbit);
continue;
}
if (in.bad()) {
throw runtime_error("IO stream corrupted");
}
cout << arr << endl;
}
in.clear();
return in;
}
//istream& input(istream& in) {
// string str;
// while (in>>str,!in.eof())
// {
// if (in.fail())
// {
// cerr << "error:input error,please try again." << endl;
// in.clear(istream::failbit);
// continue;
// }
// if (in.bad())
// {
// throw runtime_error("IO stream corrupted");
// }
//
//
// }
//}
int main(int argc,char** argv)
{
/*
习题8.7
*/
vector<string> file(3);
file[0] = "D:\\text.txt";
file[1] = "D:\\text1.txt";
file[2] = "D:\\text3.txt";
ifstream infile;
string s;
vector<string>::const_iterator iter = file.begin();
while (iter != file.end())
{
infile.open((*iter).c_str());
if (!infile) {
break;
}
input(infile);
infile.close();
infile.clear();
iter++;
}
while (!in.eof())
{
in >> arr;
//your code
}
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
istream& input(istream& in) {
string arr;
while (in >> arr, !in.eof()) {
if (in.fail()) {
cerr << "error:input error,please try again." << endl;
in.clear(istream::failbit);
continue;
}
if (in.bad()) {
throw runtime_error("IO stream corrupted");
}
cout << arr << endl;
}
in.clear();
return in;
}
//istream& input(istream& in) {
// string str;
// while (in>>str,!in.eof())
// {
// if (in.fail())
// {
// cerr << "error:input error,please try again." << endl;
// in.clear(istream::failbit);
// continue;
// }
// if (in.bad())
// {
// throw runtime_error("IO stream corrupted");
// }
//
//
// }
//}
int main(int argc,char** argv)
{
/*
习题8.7
*/
vector<string> file(3);
file[0] = "D:\\text.txt";
file[1] = "D:\\text1.txt";
file[2] = "D:\\text3.txt";
ifstream infile;
string s;
vector<string>::const_iterator iter = file.begin();
while (iter != file.end())
{
infile.open((*iter).c_str());
if (!infile) {
break;
}
input(infile);
infile.close();
infile.clear();
iter++;
}
system("pause");
return 0;
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
using namespace std;
istream& input(istream& in) {
string arr;
while (!in.eof(), in >> arr) {
if (in.fail()) {
cerr << "error:input error,please try again." << endl;
in.clear(istream::failbit);
continue;
}
if (in.bad()) {
throw runtime_error("IO stream corrupted");
}
cout << arr << endl;
}
in.clear();
return in;
}
int main(int argc, char** argv)
{
/*
习题8.7
*/
vector<string> file(3);
file[0] = "D:\\text.txt";
file[1] = "D:\\text1.txt";
file[2] = "D:\\text3.txt";
ifstream infile;
string s;
vector<string>::const_iterator iter = file.begin();
while (iter != file.end())
{
infile.open((*iter).c_str());
if (!infile) {
break;
}
input(infile);
infile.close();
infile.clear();
iter++;
}
system("pause");
return 0;
}