I need a little help, im practicing file I/O and this thing has some strange problem, and im not advanced enough to figure it out,
when i run the progrem, it prompts you to type the file name ( SUPPOSED TO HAPPEN ) BUT! after that it just closes its suppoesed to prompt you for the things to be written to it ( LINE 15 )
when i compile this i get an error on line 18,
it says, "18 | error: expected primary-expression before ',' token" ( LINE 18 IS LABELED )
NOTE: This is a different code
I think it's your & after the string variable in the first argument. The buffer should not be an adress, and even if it were I would think the & would have to be in front.
My love is like a Haddoken, it's downright fierce!
much easier and simpler than using binary i/o (read()/write()).
MadPumpkin: since there is the argument that sizeof(char) may change in the future, it may be a good idea to replace filel.size() with (sizeof(char) * filel.size()).
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
much easier and simpler than using binary i/o (read()/write()).
MadPumpkin: since there is the argument that sizeof(char) may change in the future, it may be a good idea to replace filel.size() with (sizeof(char) * filel.size()).
uhmm... because im practicing Binary I/O...
but any changes to code to make it so that it will fill the whole 'loader' variable would be much appreciated
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Maevik wrote:I think it's your & after the string variable in the first argument. The buffer should not be an adress, and even if it were I would think the & would have to be in front.
Yes. filei.read(&loader, .......
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Maevik wrote:I think it's your & after the string variable in the first argument. The buffer should not be an adress, and even if it were I would think the & would have to be in front.
Yes. filei.read(&loader, .......
well i put the '&' before "loader" now and i get this
(line 18)
error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::read(std::string*, size_t)'|
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
MadPumpkin wrote:
well i put the '&' before "loader" now and i get this
(line 18)
error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::read(std::string*, size_t)'|
That's because you are passing the function a pointer to a std::string while it's expecting a pointer to a char, where a buffer begins (char* / array of chars). I'm not too familiar with C++ I/O but I think you should create a char array as buffer and read into that. You can copy the buffer into a string to work with it if you want.
Something like that:
This will read up to 100 bytes from the stream into the char buffer and copy it into the loader string. Btw, are you sure you wanted to do filen.size() in line 18 as filen is holding your filename, not the file stream.
MadPumpkin wrote:
well i put the '&' before "loader" now and i get this
(line 18)
error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::read(std::string*, size_t)'|
That's because you are passing the function a pointer to a std::string while it's expecting a pointer to a char, where a buffer begins (char* / array of chars). I'm not too familiar with C++ I/O but I think you should create a char array as buffer and read into that. You can copy the buffer into a string to work with it if you want.
Something like that:
This will read up to 100 bytes from the stream into the char buffer and copy it into the loader string. Btw, are you sure you wanted to do filen.size() in line 18 as filen is holding your filename, not the file stream.
or you could do filei.read((char*)&loader, ... )
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
MadPumpkin wrote:
well i put the '&' before "loader" now and i get this
(line 18)
error: no matching function for call to `std::basic_ifstream<char, std::char_traits<char> >::read(std::string*, size_t)'|
That's because you are passing the function a pointer to a std::string while it's expecting a pointer to a char, where a buffer begins (char* / array of chars). I'm not too familiar with C++ I/O but I think you should create a char array as buffer and read into that. You can copy the buffer into a string to work with it if you want.
Something like that:
This will read up to 100 bytes from the stream into the char buffer and copy it into the loader string. Btw, are you sure you wanted to do filen.size() in line 18 as filen is holding your filename, not the file stream.
thank you for all of your help! everybody!! now, fantastico, about the filen.size() is there a way to do that so that i actually get the stream size instead of name of file?
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock