Difference between revisions of "CPP/Strings/Concatenate"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==Concatenate.cpp== <source lang="cpp"> #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string test; test = "hello"; int scan =…')
 
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
#include <iostream>
 
#include <iostream>
 
#include <string>
 
#include <string>
#include <sstream>
 
 
using namespace std;
 
  
 
int main()
 
int main()
 
{
 
{
   string test;
+
   std::string string1 = "Hello";
   test = "hello";
+
   string string2 = "World";
   int scan = 34;
+
 
   string test2;
+
   // Concatenate strings together using the operator +
 +
   string full = string1 + " " + string2;
  
   stringstream out;
+
   std::cout << full << std::endl;
  out << scan;
+
  test2 = out.str();
+
  cout << test << test2 << endl;
+
 
   return 0;
 
   return 0;
 
}
 
}
  
 
</source>
 
</source>

Latest revision as of 10:31, 2 February 2011

Concatenate.cpp

#include <iostream>
#include <string>
 
int main()
{
  std::string string1 = "Hello";
  string string2 = "World";
 
  // Concatenate strings together using the operator +
  string full = string1 + " " + string2;
 
  std::cout << full << std::endl;
  return 0;
}