c++ - Fstream reading by char with while -


so have code this:

    fstream abc;     abc.open(filename);      while(abc.get(currchar))     {         if(currchar==' ') ++spaces;     }       abc.close(); 

and want count spaces in given .txt file reading 1 char @ moment until eof. however, above code gives me 0s spaces. why?

i tried code, , works. believe problem sftrabbit said, path of file incorrect.

if text file in same folder main.cpp, path name of text file (e.g. textfile.txt).

if it's somewhere else, example, in c drive, path should c:/textfile.txt.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -