c++:数据类型转换问题?

来源:百度知道 编辑:UC知道 时间:2024/05/13 10:03:17
void get()
{
int i;
ifstream ifs("d:\\prime.txt");

while (ifs.good()) {

char ch = 0;
ifs.get(ch);
int k= ch; //这里怎么弄啊 ?
cout<<k<<endl;

}

}
从文件读取数据后我想把他转换成int来进行数的操作,可是转换不来,请问怎么弄啊?

从文件里读出的是一个一个的字符,分别对应响应的acs码,
int k = ch;将一个字符的acs码赋值给了K,一定不对了

可以采用函数atoi等来转化

试试将int k= ch;改为int k = (int)ch;