why doesn't creating files work on c++
Hello kind person,
I think I am either stupid or it doesn't work. here's my code :)
#include <iostream>
#include <fstream> //use this not ifstream and ofstream
#include <string>
int main() {
//file input
std::string line; //the variable needs to be initialised first
std::fstream file("file.txt"); //this will read the file and store it as the var file
file << "HII";
while (getline (file, line)) { //get line gets a line from the file...
//std::cout << line << std::endl; //value of the line well is stored in line.
}
file.close(); //close it to reduce memory usage.
//file input
//file output
std::fstream newFile("newthignie.txt"); //creates the new file.
newFile << "Hi this is definitely an old file";
newFile.close();
std::fstream fileTwo("newthingie.txt");
while (getline (fileTwo, line)) {
std::cout << line;
}
//file output
return 0;
}
and there was no output...