ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อแปลงประโยคค่า ASCII เป็นสตริงที่เทียบเท่ากัน
สำหรับสิ่งนี้ เราจะได้รับสตริงที่มีรหัส ASCII งานของเราคือการแปลงสตริงที่กำหนดให้เป็นอักขระที่เทียบเท่าและพิมพ์กลับ
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
//converting the ASCII sequence into
//character string
void convert_ASCII(string str, int len){
int num = 0;
for (int i = 0; i < len; i++) {
//appending the current digit
num = num * 10 + (str[i] - '0');
//checking if number is within range
if (num >= 32 && num <= 122) {
char ch = (char)num;
cout << ch;
num = 0;
}
}
}
int main(){
string str = "104101108108111443211911111410810033";
int len = str.length();
convert_ASCII(str, len);
return 0;
} ผลลัพธ์
hello, world!