The line of code given below is not making a new file named file7.cpp. And hence it is showing the value of tellp and tellg as -1 and seekg and seekp does not work. Moreover, if I add ios::app or ios::trunc then the file if being made and the program works perfectly. Wy is this?
std::fstream///use this
//like this
std::fstream file("help.txt");
http://www.cplusplus.com/reference/fstream/fstream/
http://www.cplusplus.com/reference/fstream/ifstream/
http://www.cplusplus.com/reference/fstream/ofstream/
It depends what you want to do. If you only want output, just use an ofstream,
std::ofstream finout("file7.txt");
If you need to both read and write to the same file in the same program, it may be useful to use fstream rather than ofstream. If you intend to read, the file should already exist. But you can force it to create a file if it doesn't exist with particular combinations of openmode as you already found.