T Nguyen
6
Q:

c++ string concatenation

#include <iostream>
#include <sstream>

int main() {
  std::string value = "Hello, " + "world!";
  std::cout << value << std::endl;

  //Or you can use ostringstream and use integers too
  //For example:

  std::ostringstream ss;
  ss << "This is an integer" << 104;
  std::cout << ss.str() << std::endl;
}
1
#include <iostream>
#include <cstdlib>

std::string text = "hello";
std::string moretext = "there";
std::string together = text + moretext;
std::cout << together << std::endl;

>> hello there
2
string first_name = "foo"
string last_name = "bar"
std::cout << first_name + " " + last_name << std::endl;
1

New to Communities?

Join the community