short lifetime of object?

Have code

1
2
3
4
5
6
7
8
9
std::ostringstream lout;

lout << ...;

if (curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, 
  lout.str().c_str()) != CURLE_OK) //CURLOPT_COPYPOSTFIELDS right_string
  return 1;
// Perform the HTTP POST.
    res =curl_easy_perform(m_curl) != CURLE_OK;


In this case curl_easy_setopt obtains wrong value (might be empty) while curl_easy_perform returns success

But in case

1
2
3
4
5
6
7
8
9
10
11
std::ostringstream lout;
string right_string;

lout << ...;

right_string = lout.str().c_str();
if (curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, 
  right_string) != CURLE_OK) //CURLOPT_COPYPOSTFIELDS right_string
  return 1;
// Perform the HTTP POST.
    res =curl_easy_perform(m_curl) != CURLE_OK;


everything seems to be OK. Is it due short lifetime of lout.str() object?
Last edited on
Topic archived. No new replies allowed.