#include <iostream>
#include <string>
int main() {
std::string str = "ABC"; // 定义一个字符串
// 遍历字符串中的每个字符,并输出其对应的ASCII码
for (char c : str) {
std::cout << "字符: " << c << ", ASCII码: " << static_cast<int>(c) << std::endl;
}
return 0;
}
#include <iostream> 和 #include <string> 分别用于输入输出和字符串处理。std::string str = "ABC"; 创建了一个包含字符 "A", "B", "C" 的字符串。for 循环 (for (char c : str)) 来遍历字符串中的每个字符。static_cast<int>(c) 将字符转换为整数类型,从而得到其ASCII码值,并通过 std::cout 输出字符及其对应的ASCII码。上一篇:c++宏
下一篇:c++ try catch用法
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站