g*********s 发帖数: 1782 | 1 the following code reads lines from the input file and skip the empty lines.
how to change the following code such that if argv[1] is not provided, we
use cin as default ifstream?
int main() {
vector lines;
ifstream input_file(argv[1]);
if ( input_file.is_open()) {
while ( !input_file.eof() ) {
string str;
getline(input_file, str);
if ( str.empty() ) {
continue;
}
else
{
lines.push_back(str);
}
}
}
} | H***a 发帖数: 735 | 2 cin is istream, just use it. |
|