Suppose a file "a.txt" which contains just one line string as below:
hello world
I don't contain any new line symbol like "\n".
void loadFileStr(istream& stream, stringstream& strs){
str << stream.rdbuf();
}
I call loadFileStr and output its read string.
int main(){
stringstream strs;
ifstream ifs("a.txt",strs);
loadFileStr(ifs, strs)
ifs.close();
std::cout << strs.str();
}
However,
strs.str()
shows hello world with newline.
hello world
'\n'
(\n) is just a space actually.
Is this rdbuf() feature or how can i read this file without any "\n"?
Aucun commentaire:
Enregistrer un commentaire