How to pass string to function as reference without the option to modify the string in C++

1 Answer

0 votes
#include <iostream>
#include <string>

void Print(const std::string& s) {
    
    // s+= " V20"; // error: no match for ‘operator+=’ (operand types are ‘const string’...
    std::cout << s;
}

int main()
{
    std::string s = "C++ Programming";	
    
    Print(s);
}




/*
run:

C++ Programming

*/

 



answered Feb 25, 2022 by avibootz

Related questions

1 answer 159 views
1 answer 125 views
1 answer 209 views
1 answer 186 views
...