Sorry to post again so soon, but I'm having a different problem. I keep trying to open a .dat file with my program. The console accepts my input, but then does nothing. I can't seem to figure out the problem. Help?
//This program will take input from a user file, read the input,
//and output the first word after the first three commas
//************************************************************
int main()
{
ifstream inFile; //begin conversion function c_str
ofstream outFile;
string fileName, //allow user name file
firstWord, //get word after first comma
secondWord, //get word after second comma
thirdWord; //get word after third comma
int wordCount = 0;
string word;
string fileName;
cout << "Input file name:" << endl; //user prompt
cin >> fileName;
inFile.open(fileName.c_str()); //open file convert c_str
if(inFile)
{
while(!inFile.eof()) // a check for we are not at the end of file.
{
inFile >> word; // we are reading from a file....
wordCount++;
cout << "Word Number "<< wordCount << ": " << word << endl;
}
inFile.close();
}
else
{
cout << "We had a problem with the file!!!" << endl;
}
If you note the code difference between what you did and mine you will see you used the wrong file stream. cout/cin are the console streams and ifstream/ofstream are the file streams, which you wanted to read from.
for your problem we might have to refine this a little better, but I don't know what to expect from your data file.
Yes, my assignment is to read the first word after three different commas from a user named file (thus the c_str). So, you're saying I need to use inFile >> word; to get the words? In that case, do I use inFile.ignore(200, ',') to get the word after the comma?