C++ file handling | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

C++ file handling

can we read and write .cpp files with file handling?

31st May 2018, 7:54 AM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar
4 Respuestas
+ 3
Yes, you can alter .cpp files using fstream.
31st May 2018, 10:18 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
No, as fstream only supports manipulation of files. It has no idea what the files are for and how are they to be used. To compile a cpp file, you can use the system() function in <cstdlib>: // C++ Version. Assuming C++11 string cpp_ver = "-std=c++11"; // Additional libraries which are required. string libs = ""; // The file name, to be compiled. // Provide Complete Path. string file = "a.cpp"; system(("g++ "+cpp_ver+" \""+libs+"\" \""+file+"\ -o \""+file.substr(0,file.size()-5)+ "\"").c_str());
31st May 2018, 10:34 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
can we compile it also using file handling?
31st May 2018, 10:19 AM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar
0
thanx
31st May 2018, 10:36 AM
Muhammad Naeem Jamali
Muhammad Naeem Jamali - avatar