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
Post a Comment