C ++,指向整数比较错误的指针 [英] C++, pointer to integer comparison error
问题描述
这是我上一个问题的延续,
在C ++中,如何读取文本文件的内容,并将其放在另一个文本文件中?
This is the continuation of my previous question, In C++, how to read the contents of a text file, and put it in another text file?
读取文件的内容并将其存储在向量中后,我要比较文件的内容与一些整数,如0,
After reading the contents of the file, and storing it in a vector, i want to compare the contents of the file with some integer like 0,
假设我的input.txt文件的内容是0100 ..
所以,打开第二个文件后,这是我给的,
assume that the contents of my input.txt file are 0100.. So, after opening the second file, this is what i have given,
string a = inputLines[0] ;
cout << a[0] << '\n';
if (a[0] == "0")
{
cout << "Match" << '\n';
}
但是,我得到的错误指向整数比较的指针,如何避免这个错误?
but, i am getting the error as pointer to integer comparison, how to avoid this error ?
推荐答案
a [0]
$ c> char ,但0
是一个 const char [2]
。您要使用字符文字'0'
(不同的引号)。
a[0]
is a char
, but "0"
is a const char[2]
. You want to use the character literal '0'
instead (different quotes).
if (a[0] == '0')
这篇关于C ++,指向整数比较错误的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!