devxlogo

Concatenating Variables

Concatenating Variables

If you need to concatenate variables of different types to form a string, use a stringstream object. The header contains the declarations of the stringstream family of classes. Using its overloaded > operator:

  #include void concat(std::string &result){ long x = 1000; double y = 5.5.; std::stringstream s; s >result; // result is now "(1000,5.5)"}

devx-admin

Share the Post: