无符号char类型变量I/O失败
I/O Fail of unsigned char typed variable
我有一个名为input.in的文件。我需要读取数字并将其存储在一个无符号char类型的变量中。我读入数字并在屏幕上打印变量的内容,我可以看到它是真的(打印1)。然而,if语句失败了。它向标准输出输出输出False。为什么会发生这种情况?如何将此数字存储到无符号字符变量中?
输入。在文件:
asus@ubuntu:~/Desktop$ cat input.in
1
我在Ubuntu工作。sizeof (unsigned char) = 1
#include <fstream>
#include <iostream>
using namespace std;
int main(){
unsigned char ucbuffer;
fstream in;
in.open("input.in",ios::binary | ios::in);
in.read((char*)&ucbuffer,1);
cout << ucbuffer << endl;
if (ucbuffer==1) cout << "True" << endl;
else cout << "False" << endl;
return 0;
}
if (ucbuffer==1)
为假。取值为"'1'
",不为"1
"。'1'
数值为49
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 为char数组调整zlib-zpipe
- 将 const 转换为 const char* 无效,我该如何解决?使用 gcc7 时失败
- 使用提升对字符串进行标记化时,将令牌转换为 char* const* 时失败
- 如何修复此 OpenCV 错误:断言失败((无符号)i < (无符号)cn) 在 cv::Vec<unsigned char,3>:::运算符 (), 文件
- C/C++:将 char[] 转换为 int 失败,无符号 char[] 到 int 有效,为什么
- MKDIR 在 C++ 系统调用中失败 - int 类型的参数与 const char* 类型的参数不兼容
- C++将 char 复制到 char 数组(调试断言失败)时,字符串不是以 null 结尾的
- 检索静态char*数组失败
- 从int到c-string(const-char*)的转换失败
- GTest和GoogleMock EXPECT_CALL在窗口中失败,在Mac上通过char*param
- 使用 int main(void) 编译失败;main(int argc, char *argv[]) successs
- 无符号char类型变量I/O失败
- 当两者都是普通char类型时,为什么is_base_of会失败?
- 为什么 ptrVec = new vector<const char*> 编译失败
- 使失败并显示错误"cannot convert ‘std::istream {aka std::basic_istream<char>}’ to ‘bool’ in return"
- 从函数返回本地var字符串失败,而本地var int和char工作正常.为什么
- 为什么传递一个char*给这个方法失败?