c++ 字符串和数字拼接


方法一:

#include <iostream>
#include <string>
#include <sstream>
using  namespace  std;
int  main()
{
     int  a = 2;
     string b =  "abc" ;
     stringstream ss;
     ss << a << b;
     cout << ss.str() << endl;
     return  0;
}
 
方法二:

#include <iostream>
using namespace std;
int main()
{
  int a = 6;
  char b[10];
  sprintf_s(b, "abc%d", a);
  cout << b << endl;
  system("pause");
  return 0;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM