C ++字符串串联运算符<< [英] C++ String Concatenation operator<<

查看:64
本文介绍了C ++字符串串联运算符<<的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经意识到自己的错误.我试图连接两个字符串.

I have realised my mistake. I was trying to concatenate two strings.

我刚刚开始学习C ++.我有一个关于字符串串联的问题.我使用时没有问题:

I have just started to learn C++. I have a problem about string concatenation. I don't have problem when I use:

cout << "Your name is"<<name;

但是当我尝试使用字符串时:

But when I try to do it with a 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 ++字符串串联运算符&lt;&lt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆