我在编程问题的解决方案中遇到了一个奇怪的代码,但我找不到任何关于它的好主意。这里,
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int count=8;
string temp="Hello ";
temp+=count+'0';
cout<<temp;
return 0;
}
Output is: Hello 8
Run Code Online (Sandbox Code Playgroud)
即使没有对整数变量进行类型转换,整数变量计数也被附加到字符串中。我想它是因为“0”而起作用的,但是这个过程或方法是什么。