Unix errors running C++ program involving struct tm -


i wrote inventory program groceries in c++ using visual studio 2012 , runs smoothly , expected. file read in command line argument , used fill deque grocery objects. function used check if grocery object expiring used time_t , struct tm. when trying run program on unix, error involving fstream

here lines of code getting errors:

    int main (int argc, char** argv) {      deque<grocery> groceries;     deque<grocery>::iterator iter;     string filename = "";      if (argc > 1) {         filename = argv[1];         fstream filedata;         filedata.open(filename, ios::in | ios::out); //**error**         //error check         if (!filedata) {             cout << "error openeing file. program aborting.\n";             return 1;         }         string name;         string expdate;         string type;         string quantity;          while (!filedata.eof()) {             grocery temp;             getline (filedata,name,'\t');             temp.setname(name);             getline (filedata,expdate,'\t');             temp.setexpdate(expdate);             getline (filedata,type,'\t');             temp.settype(type);             getline (filedata, quantity,'\n');             temp.setquantity(atoi (quantity.c_str()));             groceries.push_back(temp);         }            filedata.close();     }     return 0; } 

errors when trying run program in unix

  $ make g++ -c grocery.cpp g++ -c inventory.cpp inventory.cpp: in function âint main(int, char**)â: inventory.cpp:24:45: error: no matching function call âstd::basic_fstream<char>::open(std::string&, std::_ios_openmode)â    filedata.open(filename, ios::in | ios::out);                                              ^ inventory.cpp:24:45: note: candidate is: in file included inventory.cpp:3:0: /opt/rh/devtoolset-2/root/usr/include/c++/4.8.1/fstream:886:7: note: void std::basic_fstream<_chart, _traits>::open(const char*, std::ios_base::openmode) [with _chart = char; _traits = std::char_traits<char>; std::ios_base::openmode = std::_ios_openmode]        open(const char* __s,        ^ /opt/rh/devtoolset-2/root/usr/include/c++/4.8.1/fstream:886:7: note:   no known conversion argument 1 âstd::string {aka std::basic_string<char>}â âconst char*â make: *** [inventory.o] error 1 

makefile

mkfile    = makefile  # # definitions of list of files: # hsources  = grocery.h csources  = grocery.cpp inventory.cpp  etcsrc    = readme ${mkfile} execbin   = main allcsrc   = ${csources} objects   = ${allcsrc:.cpp=.o} allsrc    = ${etcsrc} ${hsources} ${csources} listsrc   = ${allsrc}  # # definitions of compiler , compilation options: # gcc       = g++  # # first target ``all'', , hence default, # , builds executable images # : ${execbin}  # # build executable image object files. # ${execbin} : ${objects}         ${gcc} -o ${execbin} ${objects}  # # build object file form c source file. # %.o : %.cpp         ${gcc} -c $<  # # clean , spotless remove generated files. # clean :         - rm -rf ${execbin} ${objects} 

fixed answer listed below

inventory.cpp:24:45: error: no matching function call âstd::basic_fstream<char>::open(std::string&, std::_ios_openmode)â filedata.open(filename, ios::in | ios::out); 

basic_fstream(const string&, ios_base::openmode) constructor available in c++11 mode.

you compiling code in c++98 mode. pass -std=gnu++11 g++ when compiling.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -