123456789101112131415161718
#include <iostream> #include <fstream> using namespace std; int main() { string txt; ifstream file("text.txt"); if (file.is_open()) while (file.good()) getline(file, txt); file.close(); cout << txt << endl; system ("pause"); return 0; }
Hello World
World
123456
if (file.is_open()) while (file.good()) { getline(file, txt); cout <<txt<<endl; }
Bob 20 M 1114007
Susan 22 F 1123150
1114007 Bob 20 M 1123150 Susan 22 F
123456789101112131415161718192021222324252627
#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string txt[10]; string line; int i=0; ifstream file ("example.txt"); if (file.is_open()){ while (!file.eof()){ getline(file,line); txt[i]=line; i++; } } file.close(); for (int j=0; txt[j]!="\0"; j++) cout << txt[j] << endl; system("pause"); return 0; }