Hi,
I'm trying to pass a command line argument file from main to a class function and use an ofstream object to open a file (argv). I added the file to
the run command (i'm using netbeans), and I'm looking in the active directory.
This is not working? I obviously skipped huge bits of code , but it would be too long.
Ok,
On line 6 you wrote: order.newOrder(thisOrder,&argv[1]);
and on line 9 you say: void Order::newOrder(std::vector <food*>& nOrder,char* argv[])
Evidently you are trying to pass an array using the address operator(&). You declare Order::newOrder to take as a second parameter an array of chars. They are two incompatible types. Instead of having the function take an array of pointers, try:
line 6 order.newOrder(thisOrder,argv[1]);
and on line 9 void Order::newOrder(std::vector <food*>& nOrder,string argv)
and on line 11 OutFile.open(argv,std::ios::out | std::ios::app);
Does this answer your question?
That confuses me a bit that what I had was so wrong.
I thought that I was passing a pointer to an array of char on line 9 and
the address of the array on line 6. The same as if a pointer is passed by reference?
I tried your changes and I now got all kinds of errors?
no I think I meant passing by reference using pointers. It's all confusing.
I think the compiler was complaining that I tried to convert char* to string : ?
In file included from newOrder.cpp:6:0:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream:713:7: note: void std::basic_ofstream<_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,
^
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream:713:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const char*'