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

8th Nov 2016, 5:23 AM
Rhithym SF
Rhithym SF - avatar
4 Respostas
0
You are probably trying to view another file, make sure you are in the working directory.
8th Nov 2016, 7:34 AM
A A
0
thanks all
21st Nov 2016, 1:52 PM
Rhithym SF
Rhithym SF - avatar
- 1
i think you can change " out_file<<"HELLO, WORLD!";" with cout <<"Hello World!" << endl; hope it works
8th Nov 2016, 7:03 AM
Otmane Guourch
Otmane Guourch - avatar
- 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.
8th Nov 2016, 7:26 AM
Aditya kumar pandey
Aditya kumar pandey - avatar