I use VS2010 in windows 7 to write C++ mfc program. I want to read a txt file by line and pass it to the string array.
I have tried the testByLine function but it says name "fstream" is unidentified.Also, "ios::in" seems incorrect in my windows 7 but I do not know how to correct it.
#include "stdafx.h"
#include <fstream>
std::string Value_2[5];
void testByLine()
{
char buffer[256];
fstream outFile;
outFile.open("result.txt", ios::in);
int i = 0;
while (!outFile.eof()) {
outFile.getline(buffer, 128, '\n');
Value_2[i] = buffer;
i += 1;
}
outFile.close();
}
I expected every line in the txt being passed to each element of string array Value_2.