replace
byCode:char filename[80];/
Code:string filename;
byCode:ifstream fin(filename);
Code:ifstream fin(filename.c_str());
byCode:ofstream fout(filename,ios::trunc);
Code:ofstream fout(filename.c_str(),ios::trunc);
replace
byCode:char filename[80];/
Code:string filename;
byCode:ifstream fin(filename);
Code:ifstream fin(filename.c_str());
byCode:ofstream fout(filename,ios::trunc);
Code:ofstream fout(filename.c_str(),ios::trunc);
OS: Windows 7, XUbuntu 11.10, Arch Linux
IDE: CodeBlocks
Compiler: GCC
no idea what that is...Originally Posted by h_howee
i dont think i covered any of that in my book.
char filename[80] is a C-string
#include <string>
string abc;
is a C++ string, this is a class it handles for you memory allocations (you need not to worry about the unsuffitient buffer size) and provide some useful interface like
if(abc == "Hello, World!")
So when you are programming in C++ there is no reason not to use it...
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
>> dont think i covered any of that in my book.
Many C++ books don't teach C++ strings in the beginning (primarily because they were introduced more recently than C style strings). You should be learning C++ strings first, so either switch books or supplement your book with looking things up online.
BTW, when using getline with a C++ string, there is a slightly different format:Code:getline(cin, filename);