Difference between revisions of "CPP/Strings/Concatenate"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Concatenate.cpp)
 
Line 3: Line 3:
 
#include <iostream>
 
#include <iostream>
 
#include <string>
 
#include <string>
#include <sstream>
 
 
using namespace std;
 
  
 
int main()
 
int main()
 
{
 
{
   string firstName = "jello";
+
   std::string string1 = "Hello";
   string middleName = "K.";
+
   string string2 = "World";
  string lastName = "mello";
+
  
   //concat strings together using the operator +
+
   // Concatenate strings together using the operator +
   string fullName = firstName + " " + middleName + " " + lastName;
+
   string full = string1 + " " + string2;
  
   cout << fullName << endl;
+
   std::cout << full << std::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;
}