Hi,
am editing this C++ code..
It will get the folder directory.. then i want to copy a file to sub folder in that directory.
i tried it but always gets errorsCode:#include <fstream> #include <string> #include <iostream> using namespace std; bool copyFile (const char SRC[], const char DEST[]) { std::ifstream src; // the source file std::ofstream dest; // the destination file src.open (SRC, std::ios::binary); // open in binary to prevent jargon at the end of the buffer dest.open (DEST, std::ios::binary); // same again, binary if (!src.is_open() || !dest.is_open()) return false; // could not be copied dest << src.rdbuf (); // copy the content dest.close (); // close destination file src.close (); // close source file return true; // file copied successfully } int main () { char* libvar; string filepath = "\\new\\input2.txt"; // Get the value of the LIB environment variable. libvar = getenv( "LIB" ); // C4996 // Note: getenv is deprecated; consider using getenv_s instead if( libvar != NULL ) printf( "Original LIB variable is: %s\n", libvar ); ifstream f1 ("input.txt",fstream::binary); //ofstream f2 (libvar, "\\new\\input2.txt", fstream::trunc|fstream::binary); //f2<<f1.rdbuf(); // Attempt to change path. Note that this only affects the environment // variable of the current process. The command processor's // environment is not changed. // Note: _putenv is deprecated; consider using putenv_s instead if (!copyFile ("input.txt", libvar + "\\new\\input2.txt")) std::cout << "File could not be copied successfully"; else std::cout << "File copied successfully!"; std::cin.get (); // pause for input //return EXIT_SUCCESS; // program was executed successfully return 0; }
Am using VC++ 6.0Code:error C2110: cannot add two pointers



LinkBack URL
About LinkBacks


