I am trying to write a program that reads string data from a file and that uses the ignore()function to isolate words in the string that immediately follow "commas" (and of course the space after the comma). I am attaching a code snippet to show what I am trying to do. I understand what the function does, but I have not seen it used except in an interactive program. I've only seen it written with the syntax: cin.ignore(someInt, someChar). Is is valid to use this with file input? I have successfully opened the data file and transferred the data to a string variable in the program because I have printed it out at that point. Then, when I try to use the ignore() function, I just get a cursor in my output window. Here is the code in question:
01 #include <iostream> // Access cout, cin, endl
02 #include <fstream> // Access ifstream
03 #include <string> // Access string type
04
05 using namespace std;
06
07 int main()
08 {
09 // Input variables
10 ifstream inData;
11 string fileName;
12 string inputString;
13
14 // Local variables
15 string::size_type comma;
16 string::size_type space;
17 string firstWord, secondWord, thirdWord;
18
19
20 // Prompt user for data filename
21 cout << endl << "Enter the input file name: ";
22 cin >> fileName;
23
24 //Open file
25 inData.open(fileName.c_str());
26 getline(inData, inputString); // inputString now holds text of
27 // text file
28 cout << inputString << endl << endl;
29 cin.ignore(200, ',');
30 space = inputString.find(" ");
31 cout << space;
The last two lines of code are just my attempt to see where the reading marker is (position). Thanks in advance for any help.