如何将数组中的数据转换为字符串 c++
How to convert data in array to string c++
我有包含 1 或 0 的数组。我想附加它并成为一行字符串。目前我失败了。这是我的代码。请帮忙,因为我无法完成它。每次我将最终结果加载到控制台时,只有笑脸,而不是 1 或 0。请帮忙
int pixelValueArray[256];
String testing;
for(int d=0;d<256;d++)
{
testing.append(1,pixelValueArray[d]);
}
cout<<testing;
Std 提供了函数 std::to_string()(自 c++11 以来)将 int 等数据类型转换为 std::string: http://en.cppreference.com/w/cpp/string/basic_string/to_string 。也许这可以帮助你。
整数
的 ASCII 值由 '0' + digit
给出。
for(int i = 0; i < 256; i++)
testing.append(1, '0' + pixelValueArray[i]);
或者您可以使用更简单的+=
for(int i = 0; i < 256; i++)
testing += '0' + pixelValueArray[i];
相关文章:
- wcstombs_s(),转换字符串的长度
- 使用 CStringW/CStringA 和 CT2W/CT2A 转换字符串有什么区别?
- 无法转换字符串插入函数的参数
- 转换字符串向量:基于先前的值跳过元素
- 从中间器转换字符串不起作用,出了什么问题?
- 失败的证明转换字符串到枚举类
- 如何使用正则表达式和提升转换迭代器标记和转换 c 字符串
- 使用java jni时转换字符串类型
- 如何避免在转换字符串令牌流时重复istringstream构造
- 阿托伊未正确转换字符串
- C++,转换字符串,使连续下划线序列变为单个下划线
- 使用长算术转换字符串
- 转换字符串十进制数时的精度
- 将词法转换字符串提升为双精度
- 使用marshal_as函数转换字符串的性能
- C++不会从数据转换字符串
- 无论如何,在c++ /Qt中转换字符串到结构中的字段
- C++ 隐式类型转换字符串 -> int?
- 转换字符串到浮点数,c++实现
- 用于转换字符串大小写的函数