I am writing strings to a text file using:
ofstream ofs("ofs.txt", ios_base::binary);
std::string str = "Hi";
for (int i = 0 ; i < 10000000 ; i++) {
ofs << str.c_str();
ofs << "\n" ;
}
However, this takes long time to execute. Can anybody help me how to improve performance of the above. Or any other faster way to writing strings to file.
Thanks.
In several cases I found that C++ I/O streams tend to be slower than C
<stdio.h> FILE*.I had a confirmation also in the following test:
Compiled with VS2010 SP1 (VC10):
Test result: