If i wanted to save entire input till EOF into 1 string, any idea how I would do this?
(besides getline and concating strings every time, thats the only solution I can think of)
Thanks
This is a discussion on saving entire input into 1 string? within the C++ Programming forums, part of the General Programming Boards category; If i wanted to save entire input till EOF into 1 string, any idea how I would do this? (besides ...
If i wanted to save entire input till EOF into 1 string, any idea how I would do this?
(besides getline and concating strings every time, thats the only solution I can think of)
Thanks
Given a std::istream named in, one way is:
But I recall from an old thread that a more efficient method works along the lines of what you have described. Perhaps you can search and find out what exactly was the most efficient method we considered.Code:std::stringstream ss; ss << in.rdbuf(); std::string str = ss.str();
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
Try to keep things simple. If getline works fine in your situation, leave the alternate. Making things complex for yourself will reap no benefits. Curiosity however is fine and a good thing.