1

I wrote a callback function to write data into a string variable transferred by curl_easy_perform.

I've found that the callback function would be called several times (I don't know exactly how many ).

Will The string variable content be overwritten with the subsequent call? How to implement this?

P.S. I've found that link useful.

Bruce Yang
  • 367
  • 1
  • 5
  • 17
  • The string content will overwrite if that is how you wrote your function. To stop it overwriting you have to rewrite your function to append instead of overwrite. The easiest way would be to use `std::string::append`. If you post the function you wrote, you'll be able to get some help with improving it. – john Nov 20 '13 at 08:36

1 Answers1

1

The number of times the callback is called depends on how much data there is to read.

If you are using C++, then use std::string, and you won't have that trouble.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thank for your quilckly rely. I'am using C++. That conflict with my previous C++ knowledge that variable would be overwrote when a function called several times. How the libcurl implement this feature? – Bruce Yang Nov 20 '13 at 08:40
  • @BruceYang You append to the buffer you have. With `std::string` you just use the [`+=` operator](http://en.cppreference.com/w/cpp/string/basic_string/operator%2B%3D), as in `someString += someOtherString;` – Some programmer dude Nov 20 '13 at 08:42