Revision: 2581
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 12, 2007 15:58 by pckujawa
Initial Code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inputFile;
string line;
string input;
cout << "Enter a file name to scan" << endl;
cin >> input;
cout << endl;
cout << "Your file was: " << input << endl;
try {
inputFile.open(input.data(), ios::in);
}
catch (...) {
cout << "File open error" << endl;
}
if ( !inputFile.is_open() ) {
return -1;
}
while (! inputFile.eof() )
{
getline(inputFile, line, ' ');
cout << "__________ " << line << endl;
}
inputFile.close();
cin >> input; // Just used to keep the console open in Visual C++
return 0;
}
Initial URL
Initial Description
Use to get console input from the user for a file name (in the current directory) and read in from that file.
Initial Title
Filename input and reading
Initial Tags
c
Initial Language
C++