#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
int id = 7;
unsigned char tete[7] = {0xff, 0x01, 0x00, 0x03, 0x00};
tete[5] = id & 0xff;
tete[6] = (tete[1] + tete[2] + tete[3] + tete[4] + tete[5]) & 0xff;
stringstream ss;
ss << hex << setfill('0');
for (size_t i = 0; i < 7; ++i) {
ss << setw(2) << static_cast<unsigned int>(tete[i]);
}
cout<<"original : "<<ss.str()<<endl;
string s_toupper = ss.str(); // 待转换的字符串
for (char &c : s_toupper) {
c = toupper(c); // 转换为大写
}
cout <<"upper : "<<s_toupper << endl; // 输出转换后的字符串
string s_tolower = ss.str(); // 待转换的字符串
for (char &c : s_tolower) {
c = tolower(c); // 转换为小写
}
cout <<"lower : "<<s_tolower << endl; // 输出转换后的字符串
return 0;
}
c++ 十六进制数转string类型并变为大写或小写
最新推荐文章于 2024-07-15 15:17:48 发布