I made code that read file as vector. But it's terribly slow.(it takes 12sec to read about 430000lines) What's wrong with my code? When I do same thing in C# it takes only 0.5 ~ 1 sec.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
bool getFileContent(string fileName, vector<string> &vecOfStrs)
{
ifstream in(fileName.c_str());
if (!in)
{
std::cerr << "Cannot open the File : " << fileName << std::endl;
return false;
}
string str;
while (getline(in, str))
{
if (str.size() > 0)
{
vecOfStrs.push_back(str);
}
}
in.close();
return true;
}
int main()
{
string my_file_path = "C:/Users/user/Desktop/myfile.txt";
vector<string> lines;
bool result = getFileContent(my_file_path, lines);
if (result)
{
cout << lines.capacity() << endl;
}
}