c++ - Why isn't my fstream opening correctly? -


I think this is a silly question, but I do not know why my file is not open most First I tried to pass the file name alone because it was in my working directory, and when I did not work, then I supplied the entire path that did not work either. Is there a reason that my file will not open in the following code? Maybe it's something very easy that I am missing, and I thought that a new eye can be helped.

There is no error code because it is a runtime error when I debug, my code does not take action before if (f.is_open ()) line Am I forgetting something? My path should be correct because I paste it directly from the file explorer.

Any help is welcome, and an explanation will be appreciated.

Note: My subtraction argument may be wrong, but do not worry about that part of the code.

  zero QuizKey :: readFromFile (string path) {fstream f; F.open (path); String line; If (f.is_open ()) {while (getline (f, line)) {int periodLocation = line.find ("."); Int firstPipe = line.find ("|"); Int secondPipe = line.find ("|", FirstPip); Int thirdpipe = line.find ("|", second pipe); Set set answer; Set.answer = line.substr (duration: location + 1, first pipe - duration space - 1); Set.two = line.substr (first pipe + 1, second pipe - first pipe-1); Set.three = line.substr (second pipe + 1, third pipe - second pipe-1); Set.four = line.substr (third pipe + 1, line.line () - third pipe - 1); Key.push_back (set); If you are in Windows and you are copying directly and copying from Explorer then}}}}  

You may have forgotten to avoid a slash in the file path, it should be "c: \\ foo \\ bar.txt" .

Additionally, f.open (path.c_str ())

Should be

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -