Code
  • 首页
  • cpu-architecture
  • performance
  • c++
  • branch-prediction
  • java
2025-05-20 09:00:02

在c++中,如何将int值附加到字符串中?

c++intstdstring
int i = 4;
string text = "Player ";
cout << (text + i);

我想打印参与人4。

上面显然是错误的,但它显示了我在这里要做的事情。是否有一个简单的方法来做到这一点,或者我必须开始添加新的包含?


当前回答

cout << text << i;
2008-09-15 17:10:54

其他回答

cout << "Player" << i ;
2008-09-15 17:10:45
printf("Player %d", i);

(你可以给我的答案投票;我仍然讨厌c++的I/O操作符。)

:-P

2008-09-15 17:13:54
cout << text << i;
2008-09-15 17:10:54
cout << text << " " << i << endl;
2008-09-15 17:12:34
cout << text << " " << i << endl;
2008-09-15 17:10:57

推荐文章

  • decltype(auto)的一些用途是什么?
  • Shared_ptr转换为数组:应该使用它吗?
  • Printf与std::字符串?
  • 禁用复制构造函数
  • 只接受特定类型的c++模板
  • c#和Java中的泛型有什么不同?和模板在c++ ?
  • 如何舍入一个双到最近的Int在迅速?
  • c++ 11中的递归lambda函数
  • 在c++中指针使用NULL或0(零)吗?
  • 在c++中,如何将int值附加到字符串中?
  • 就性能而言,使用std::memcpy()还是std::copy()更好?
  • 为什么布尔值是1字节而不是1位?
  • 四舍五入到一个数字的最接近倍数
  • 模板默认参数
  • c++ auto关键字。为什么它是魔法?

aliyun

最新文章

  • 如何删除默认的导航栏空间在SwiftUI导航视图
  • 我可以列出所有的标准Go包吗?
  • 证书验证失败:无法获得本地颁发者证书
  • 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
  • 打开同一目录两次
  • 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
  • NullInjectorError: AngularFirestore没有提供程序
  • 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
  • 从元组/数组值派生联合类型
  • 如何在Angular2中截断文本?
  • 安装tzdata非交互式
  • ionic 2 - Error在Android Studio中找不到Gradle的安装版本
  • 如何查看所有地区所有正在运行的Amazon EC2实例?
  • 当使用pip3安装包时,“Python中的ssl模块不可用”
  • 安装APK时出现错误

标签

cpu-architectureperformancec++branch-predictionjavaundogit-commitgitversion-controlgit-remotegit-pushgit-branchgit-pullgit-fetchpythongeneratoriteratorjsonmime-typescontent-typearraysjavascriptgit-addcode-formattingcstandards-complianceoperatorscommentsdynamic-memory-allocationstackmemory-managementheap-memorylanguage-agnosticoverwritebackground-colorbrowserhtmldomjqueryvisibilityuse-strictsyntaxjslintremote-branchgit-checkoutpython-moduleidiomsprogram-entry-pointnamespacesbranch
2025 code 京ICP备15047053号-1