fstream input;
input.open("Data.txt", ios::in);
string city;
if (input.fail())
{
cout << "File does not exist" << endl;
cout << "Exit program" << endl;
}
while (!input.eof()) // Continue if not end of file
{
getline(input, city, '.');//getline(file,string,delimit char)
cout << city << endl;
}
input.close();
//Another solution
fstream file2;
file2.open("Data.txt", ios::in);
string line;
cout << "Data file:
";
if (file2.is_open()) { //check if the file is open
while (getline(file2, line)) {
cout << line << endl;
}
file2.close();
}
fstream input;
input.open("Data.txt", ios::in);
string city;
if (input.fail())
{
cout << "File does not exist" << endl;
cout << "Exit program" << endl;
}
while (!input.eof()) // Continue if not end of file
{
getline(input, city, '.');//getline(file,string,delimit char)
cout << city << endl;
}
input.close();
//Another solution
fstream file2;
file2.open("Data.txt", ios::in);
string line;
cout << "Data file:
";
if (file2.is_open()) { //check if the file is open
while (getline(file2, line)) {
cout << line << endl;
}
file2.close();
}