reading line in c++ code example
Example 1: how to read a line from the console in c++
#include <string>
std::string str;
std::getline(std::cin, str);
Example 2: c++ read file line by line
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
fstream newfile;
newfile.open("tpoint.txt",ios::out);
if(newfile.is_open())
{
newfile<<"Tutorials point \n";
newfile.close();
}
newfile.open("tpoint.txt",ios::in);
if (newfile.is_open()){
string tp;
while(getline(newfile, tp)){
cout << tp << "\n";
}
newfile.close();
}
}