c++ - ifstream::open not working in Visual Studio debug mode -


I am all Ivestrym questions on SEO and I have trouble reading a simple text file. I am working with Visual Studio 2008.

This is my code:

  // CPPFileIO.cpp: defines the entry point for the console application // # include "stdafx.h" #included & Lt; Fstream & gt; # Include & lt; Conio.h & gt; # Include & lt; Iostream & gt; #include & lt; String & gt; using namespace std; Int _tmain (int argc, _TCHAR * argv []) {ifstream infile; Infile.open ("input.txt", ifstream :: in); If (infile.is_open ()) {while (infile.good ()) cout & lt; & Lt; (Four) infile.get (); } And {cout & lt; & Lt; "unable to open file."; } Infile.close (); _getch (); Return 0; }  

I have confirmed that input.txt file argv [0] . Open system will not work only.

I still have trouble in debugging - can not I set a clock at infile.good () or infile.is_open () ? I continue

  Error: member function does not exist.  

Edit: List the update code with the full code from the .cpp file.

Update: The file was not in the current working directory, this directory is where the project file located was moved to it and debugging it in VSNET Works on

Try to time to use bitwise or operator to specify the open mode.

  infile.open ("input.txt", iOS :: ate | ios :: in);  

The parameter is a bitmask ios :: ate is used to open the file for attachments, and ios :: in Is used to open the file to read the input.

If you want to read just a file, you can probably use it:

  infile.open ( "input.txt", ios :: in) ;  

The default open mode for an ifstream is in iOS :: So, you can get rid of that completely now using the following code for me using G ++ is.

  #include & lt; Iostream & gt; # Include & lt; Fstream & gt; # Include & lt; Cstdio & gt; using namespace std; Int main (int argc, char ** argv) {ifstream infile; Infile.open ("input.txt"); If (infail) {while (infile.good ()) cout & lt; & Lt; (Four) infile.get (); } And {cout & lt; & Lt; "unable to open file."; } Infile.close (); Getchar (); Return 0; }  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -