0
i want to store a message
hello, i want to ask..how does i want to store a message hello world onto the open file name hello.txt? i already create a code but seem dont have an output this is my code: #include<iostream> #include<fstream> using namespace std; int main() { ofstream out_file; out_file.open("hello.txt"); out_file<<"HELLO, WORLD!"; out_file.close(); return 0; } 😁😁😁 sorry iam just new to this course
4 Antworten
0
You are probably trying to view another file, make sure you are in the working directory.
0
thanks all
- 1
i think you can change " out_file<<"HELLO, WORLD!";" with
cout <<"Hello World!" << endl;
hope it works
- 1
to get output use ifstream. Call your file print it while you not reach EOF end of file. like this code
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream MyFile1("test.txt");
MyFile1 << "This is awesome! \n";
MyFile1.close();
string line;
ifstream MyFile("test.txt");
while ( getline (MyFile, line) ) {
cout << line << '\n';
}
MyFile.close();
}
but try it in offline c++ compiler.