Answers for "how to read line c++"

C++
13

c++ read file line by line

#include <iostream>
#include <ifstream>
#include <string>

using namespace std;

ifstream file("file.txt");
if (file.is_open())
{
	string line;
	while (getline(file, line))
    {
    	// note that the newline character is not included
        // in the getline() function
    	cout << line << endl;
    }
}
Posted by: Guest on January-05-2020
1

how to read a line from the console in c++

#include <string>
std::string str;
std::getline(std::cin, str);
// The output of std::getline(std::cin, str) will be stored in str.
Posted by: Guest on November-06-2020

Browse Popular Code Answers by Language