I'm trying to read in data from a text file. How would I do that from C++. Do I have use the input mode?
open(fileName,ios::in)
If so, then how to I read in data, in string form?
Thanks
I'm trying to read in data from a text file. How would I do that from C++. Do I have use the input mode?
open(fileName,ios::in)
If so, then how to I read in data, in string form?
Thanks
This is the easiest way to do this:
#include <fstream>
#include <string>
#include <vector>
int main () {
std::string str;
std::vector<std::string> vec;
std::ifstream myfile("example.txt"); //name of your txt file
while (std::getline(myfile, str)) { // read txt file line by line into str
vec.push_back(str); //you have to store the data of str
}
myfile.close(); // optional, streams are RAII types
// and thus close automatically on leaving scope
}