我是第一次学习C++.我以前没有编程背景.
我在书中看到了这个例子.
#include <iostream>
using::cout;
using::endl;
int main()
{
int x = 5;
char y = char(x);
cout << x << endl;
cout << y << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个例子很有意义:打印一个整数及其ASCII表示.
现在,我创建了一个包含这些值的文本文件.
48
49
50
51
55
56
75
Run Code Online (Sandbox Code Playgroud)
我正在编写一个程序来读取这个文本文件 - "theFile.txt" - 并希望将这些数字转换为ASCII值.
这是我写的代码.
#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
using std::ifstream;
int main()
{
ifstream thestream;
thestream.open("theFile.txt");
char thecharacter;
while (thestream.get(thecharacter))
{
int theinteger = int(thecharacter);
char thechar = char(theinteger);
cout << theinteger << "\t" << …Run Code Online (Sandbox Code Playgroud)