[英]Qt error iso c++ forbids comparison between pointer and integer -fpermissive
I use Qt 4.5.1 and here in this console application when I want to receive user's input at if statement line it gets this error: 我使用Qt 4.5.1,并且在此控制台应用程序中,当我想在if语句行接收到用户输入时收到此错误:
iso c++ forbids comparison between pointer and integer -fpermissive
iso c ++禁止比较指针和整数-fpermissive
here's my code: 这是我的代码:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
char ans;
QDir mDir;
QString mPath("A:/inetpub/wwwroot/xampp");
if (mDir.exists(mPath))
qDebug() << mDir.exists();
else {
qDebug() << "Do you wanna create the path? Y / N";
// getline(cin, ans);
cin >> ans;
if (ans == "y") {
qDebug() << "Now I create one";
mDir.mkpath(mPath);
}
}
return a.exec();
}
I have another trivial separated question as well; 我还有另一个琐碎的分开的问题; why I can't use
getline(cin,string)
function this way in Qt? 为什么我不能在Qt中以这种方式使用
getline(cin,string)
函数?
You are comparing string literal
with char
您正在将
string literal
与char
比较
if (ans == "y")
Should be 应该
if (ans == 'y')
Answering your second question. 回答第二个问题。
getline()
is used to read a string or a line from input stream not single char
. getline()
用于从输入流而非单个char
读取字符串或行。 and the syntax goes as below. 语法如下。
istream& getline (istream& is, string& str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.