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.
Here is the entire code.
Here is the offending code:Code:void FileReader::file_count() { bool match; string temp; int back = ignored_words.size(); cout << "\n\n\tExample: C:\\myfile.txt" << "\n\t-------" << "\n\n\tEnter the path to your file to count: "; cin >> temp; infile.open(temp.c_str(),ios::binary); if(infile.fail()) //Any attempt to open always fails { cout << "\n\n\t\aCannot Locate File -OR- File Does Not Exist!" << "\n\n\tPress [ENTER] to continue..."; [/color] cin.ignore(); cin.get(); return; }
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.
Program compiles ok, but with these warnings.. if anyone has any suggestions on how to correct these warnings i'd be much greatful.
--------------------Configuration: filereader - Win32 Debug--------------------
Compiling...
filereader.cpp
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,st d::allocator<char>
>,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(39) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_trait s<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::std::vector<std::basic_string<char,std::char_tr aits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > > >(const std::allocator<std:
:basic_string<char,std::char_traits<char>,std::all ocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std: :char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,st d::allocator<char> >,std:
:basic_string<char,std::char_traits<char>,std::all ocator<char> > &,std::basic_string<char,std::char_traits<char>,st d::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(39) : while compiling class-template member function '__thiscall std::vector<std::basic_string<char,std::char_trait s<char>,std::allocator<char> >,std::allocator<std::basic_string<c
har,std::char_traits<char>,std::allocator<char> > > >::std::vector<std::basic_string<char,std::char_tr aits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > > >(const std::allocator<std:
:basic_string<char,std::char_traits<char>,std::all ocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > >
>::vector<std::basic_string<char,std::char_traits< char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_trai ts<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > >
>::~vector<std::basic_string<char,std::char_traits <char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_ traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
Linking...
filereader.exe - 0 error(s), 4 warning(s)