There are following two major issues associated with CPP programs:
When a program is terminated, the entire data is lost.
If you have to enter a large number of data, it will take a lot of time to enter them all in the different programs.
Suggest a solution and elaborate the same with the help of suitable examples.
// In order not to need to re - enter all the data, you can use either the databases where the values will be saved
// or the easiest way to implement is to save the data to a file
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream fout;
fout.open("Data.txt");
string set[3];
for (int i = 0; i < 3; i++)
{
cout << "Enter string: ";
cin >> set[i];
if (i == 2)
{
fout << set[i];
break;
}
fout << set[i] << " ";
}
fout.close();
cout << endl;
cout << "Now will get data from file!" << endl;
ifstream fin;
fin.open("Data.txt");
string temp;
while (!fin.eof())
{
fin >> temp;
cout << temp << endl;
}
fin.close();
return 0;
}
Comments
Leave a comment