【发布时间】:2020-09-14 09:59:48
【问题描述】:
我打算将一个字符串转换为一个数字数组。例如下面的代码运行良好:
// A program to demonstrate the use of stringstream
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string s = "12345";
// object from the class stringstream
stringstream geek(s);
// The object has the value 12345 and stream
// it to the integer x
int x = 0;
geek >> x;
// Now the variable x holds the value 12345
cout << "Value of x : " << x;
return 0;
}
如何处理一个非常大的字符串。例如, 字符串 s = "77980989656B0F59468581875D719A5C5D66D0A9AB0DFDDF647414FD5F33DBCBE"
我需要将它存储到一个字符数组 arr[32] 中。 arr[0] 应该有 0x77,arr[1] 应该有 0x98 等等。考虑到字符串 s 是 64 字节。我的数组长 32 个字节。
有人可以帮忙吗?
【问题讨论】:
-
是否要将字符串的数字存储到数组中?
-
因此,您实际上是在问如何将表示十进制数的字符串转换为表示十六进制数的字符串。可能值得注意的是,作为问题的输入和输出。
-
@Abhishek 是的。我的字符串代表十六进制数。
-
@goodvibration 我的字符串代表十六进制数。
标签: c++ arrays string stringstream