mardi 28 mars 2017

ifstream.rdbuf behaves in an unexpected way

I used following code to read a sample text file and read it in to a string.with this i have tried several different approaches to do the same and all gave me the same result. the intention was to read the file as it is . as i have examined the final string contains data with spaces.

Actual file contains = harshana

the resulting string = h a r s h a n a

std::ifstream inFile(fileName,std::fstream::binary);

if (!inFile.is_open()) return NULL;

stringstream stream;
stream << inFile.rdbuf();

string str = stream.str();

char *buf = new char[str.length()];
str.copy(buf, str.length());

Aucun commentaire:

Enregistrer un commentaire