+ 5
someone explain files please.
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
+ 5
good
can u explain how to store and retrieve from a file in cpp
if possible. please.
+ 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.
+ 3
Yes, I know that. This code is not written by me. I have use tutorial code. But thanks, I will change it
+ 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);