相关疑难解决方法(0)

在C++中将int转换为字符串的最简单方法

在C++中转换int为等效的最简单方法是什么?string我知道两种方法.有没有更简单的方法?

(1)

int a = 10;
char *intStr = itoa(a);
string str = string(intStr);
Run Code Online (Sandbox Code Playgroud)

(2)

int a = 10;
stringstream ss;
ss << a;
string str = ss.str();
Run Code Online (Sandbox Code Playgroud)

c++ string int type-conversion

1488
推荐指数
16
解决办法
273万
查看次数

如何连接std :: string和int?

我认为这很简单,但它存在一些困难.如果我有

std::string name = "John";
int age = 21;
Run Code Online (Sandbox Code Playgroud)

如何组合它们以获得单个字符串"John21"

c++ int concatenation stdstring

631
推荐指数
16
解决办法
61万
查看次数

如何在C中连接字符串和int?

我需要在循环的每次迭代中形成一个字符串,其中包含循环索引i:

for(i=0;i<100;i++) {
  // Shown in java-like code which I need working in c!

  String prefix = "pre_";
  String suffix = "_suff";

  // This is the string I need formed:
  //  e.g. "pre_3_suff"
  String result = prefix + i + suffix;
}
Run Code Online (Sandbox Code Playgroud)

我试图使用的各种组合strcat,并itoa没有运气.

c string

66
推荐指数
2
解决办法
15万
查看次数

标签 统计

c++ ×2

int ×2

string ×2

c ×1

concatenation ×1

stdstring ×1

type-conversion ×1