someone explain files please. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

someone explain files please.

9th Dec 2016, 10:03 AM
F.Heeh. 2nd Yr. Hebron University‏‎
F.Heeh. 2nd Yr. Hebron University‏‎ - avatar
5 Answers
+ 5
There is two types of files in programing. Binary and text. Text means file that contains text like you have write something in notepad. Binary files are images, videos, other files that is not text files. They also consists text but it is not understandable by human. Hope it helps you
9th Dec 2016, 10:15 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 5
good can u explain how to store and retrieve from a file in cpp if possible. please.
9th Dec 2016, 11:25 AM
F.Heeh. 2nd Yr. Hebron University‏‎
F.Heeh. 2nd Yr. Hebron University‏‎ - avatar
+ 3
Well, here it is #include <iostream> #include <fstream> using namespace std; int main () { ofstream MyFile1("test.txt",ios::app); MyFile1 << "This is awesome! \n"; MyFile1.close(); string line; ifstream MyFile("test.txt"); while ( getline (MyFile, line) ) { cout << line << '\n'; } MyFile.close(); } I have use code from tutorial. Hope it helps you to understand it.
9th Dec 2016, 1:46 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 3
Yes, I know that. This code is not written by me. I have use tutorial code. But thanks, I will change it
10th Dec 2016, 1:43 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
@Aditya ofstream MyFile1("test.txt"); Possibly your code will clear the text.txt when its opened again. if you add ios::app it will append the previous text with the recent text when text.txt is opened again for input. ofstream MyFile1("test.txt", ios::app);
9th Dec 2016, 8:26 PM
Franky BrainBox
Franky BrainBox - avatar