Possible Duplicate:
What is the best way to slurp a file into a std::string in c++?
Im trying to store a whole text file as a string,
how can I dynamically store any amount of characters the text file may contain?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The C++ Standard Library provides the
std::stringtype for dynamically sized strings. It is a typedef forstd::basic_string<char>. There’s a useful reference at cppreference.com.For reading lines from a file into a
std::string, take a look atstd::getline. You can use it to get a line from a file as follows:Be sure to check the stream (it is returned by
std::getline) to see if everything went okay. This is often done in a loop: