C++ read from .txt file and assign to string
Go to solution
Solved by databreach,
You should be able to do so using:
#include <sstream>
#include <string>
std::string line;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int a, b;
if (!(iss >> a >> b)) { break; } // error
// process pair (a,b)
}
More solutions here:
https://stackoverflow.com/questions/7868936/read-file-line-by-line-using-ifstream-in-c
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now