c++ - Am I missing something? I keep outputting "No file found!" -


void getbookdata(booktype books[], int& noofbooks) {     ifstream infile;     string file = "bookdata.txt";     infile.open(file.c_str());     if (infile.fail()) {         cout << "no file found!" << endl;         infile.clear();     }     while (true) {         string line;         getline(infile, line, '\r');         if (infile.fail()) {             break;           }         cout << "line: " << line << endl;     }     infile.close(); } 

i've tried putting file in every location can think of, somehow it's not loading in. or, more likely, i'm doing else wrong. isn't end result of code supposed like, right i'm trying read out file line line.

i guess need debugging why happening you.

try adding more code routine determine going on. 1 thing try call getcwd.

#include <unistd.h>  ... char buf[path_max]; std::cout << "cwd: " << getcwd(buf, sizeof(buf)) << std::endl; ... 

this should report program thinks running from.

start first, , guessing next steps become obvious you.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -