- 论坛徽章:
- 14
|
你这代码很奇葩。
对于你的问题,If the function extracts no elements, it calls setstate(failbit). In any case, it returns *this.- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cassert>
- using namespace std;
- int main()
- {
- {
- ifstream in("strfile.cpp");
- assert(in);
- ofstream out("strfile.out");
- assert(out);
- size_t lineno = 1;
- for( string line; getline(in,line); ++lineno )
- {
- cout << line << endl;
- out << lineno << ": " << line << '\n';
- }
- }
- ifstream in("strfile.out");
- assert(in);
- for( string line; getline(in,line); )
- {
- size_t pos = line.find(':');
- cout << line.c_str()+pos+2 << endl;
- }
- return 0;
- }
复制代码 |
|