C ++字符串缩写 [英] C++ String concatination
本文介绍了C ++字符串缩写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经意识到自己的错误。我试图连接两个字符串。
I have realised my mistake. I was trying to concatenate two strings.
感谢帮助!
我刚刚开始使用c ++。我有关于琴弦污染的问题。
使用时我没问题:
I have just started to c++. I have a problem about string contamination. I don't have problem when I use:
cout <<"Your name is"<<name;
但是当我尝试使用字符串时:
But when I try to do it with string:
string nametext;
nametext = "Your name is" << name;
cout << nametext;
我遇到了错误。如何连接两个字符串?
I got an error. How can I concatenate two strings?
谢谢!
推荐答案
对于C ++中的字符串连接,应使用 +
运算符。
For string concatenation in C++, you should use the +
operator.
nametext = "Your name is" + name;
这篇关于C ++字符串缩写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文