Ensuring That a Function Doesn't Modify an Argument - C++ Data Type

C++ examples for Data Type:const

Description

Ensuring That a Function Doesn't Modify an Argument

Demo Code

#include <iostream>
#include <string>

void concat(const std::string& s1, const std::string& s2, std::string& out) {
   out = s1 + s2;/*ww w.ja va  2  s .  co m*/
}

int main() {

   std::string s1 = "test ";
   std::string s2 = "defg";
   std::string s3;

   concat(s1, s2, s3);

   std::cout << "s1 = " << s1 << '\n';
   std::cout << "s2 = " << s2 << '\n';
   std::cout << "s3 = " << s3 << '\n';
}

Result


Related Tutorials