File I/O Issue

This is a discussion on File I/O Issue within the C++ Programming forums, part of the General Programming Boards category; I am trying to open() a user specified .dat file. No matter how I enter the path to the file, ...

File I/O Issue

I am trying to open() a user specified .dat file. No matter how I enter the path to the file, my attempts always fail(). I've seen this technique work successfully here, but doesn't seem to work in my program.

As you can see, I've experimented with the ios bitflags to see if I could get any results but to no avail.

The example I am using is a file called 'text.dat' which is located in my C:\ folder.. so when prompted by the program (menu option #2) I am entering c:\text.dat

Here are the program specification:

A C++ program to read a file (designated by the user) and count the occurrences and frequency of the words in the file. You are to ignore all white spaces and punctuation (still waiting on this part until I can get file I/O working)

The program should ask the user for the file name. It should also read a file- ignore.dat which contains a list of words (one per line) to ignore in the counting process. The output of your program should be each word, the number of occurrences, and the percentage of occurrences, displayed in descending order of frequency. (Although this is a homework-like exercise, I assure you it is not homework.. just working on book exercises on my own for personal fun)

General Strategy:

Load a vector of strings with 'ignore' words. Read user specified file word at a time. Compare to vector of ignores. IF no match, increment word counter. IF match, try again. "Vector of strings" strategy is based on this google search.

>getline(infile, temp.c_str());
This doesn't work because getline() expects a string, not a pointer to const char.

>infile.getline(temp,'\n');
This doesn't work because infile.getline() expects a pointer to char, not a string.

>infile.getline(temp.c_str,'\n');
This doesn't work because it's a syntax error, and it wouldn't work even if you added the parens to c_str() because it gives you a pointer to const char, not a pointer to char.

And using <stream>.eof() as a loop condition will bite you eventually. A better solution is to use the return value of your input function as the condition: