I have a function in a program that reads a text file into a string. My problem is that later processes needs the string to be clean. In the sense that there's no white spaces, break rows etc. If someone could help me with this it would make my day. :-)
The function:
Code:
string file2String(const string &fileName)
{
ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate);
if(!ifs)
{
cerr << "Error : File could not be opened." << endl;
exit(1);
}
ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
vector<char> bytes(fileSize);
ifs.read(&bytes[0], fileSize);
return string(&bytes[0], fileSize);
}
Cheers!