简体   繁体   English

Qt错误iso c ++禁止比较指针和整数-fpermissive

[英]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 literalchar比较

  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.

相关问题 错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive] - Error] ISO C++ forbids comparison between pointer and integer [-fpermissive] ARDUINO:ISO C++ 禁止指针和整数之间的比较 [-fpermissive] - ARDUINO: ISO C++ forbids comparison between pointer and integer [-fpermissive] ISO C ++禁止比较指针和整数[-fpermissive] - ISO C++ forbids comparison between pointer and integer [-fpermissive] C ++错误:ISO C ++禁止指针和整数之间的比较[-fpermissive] - C++ Error: ISO C++ Forbids Comparison Between Pointer and Integer [-fpermissive] ISO C++ 禁止在 Arduino c 串行通信中比较指针和整数 [-fpermissive] 错误 - ISO C++ forbids comparison between pointer and integer [-fpermissive] error in Arduino c serial communication 得到错误:“ISO C ++禁止指针和整数之间的比较[-fpermissive]”如何修复? - Getting error: “ISO C++ forbids comparison between pointer and integer [-fpermissive]” How do I fix? ISO C ++禁止在devc ++中比较指针和整数[-fpermissive]错误 - ISO C++ forbids comparison between pointer and integer [-fpermissive] error in devc++ 错误:ISO C++ 禁止在 Lambda ZC1C42145268E617A945D 中的指针和 integer [-fpermissive] 之间进行比较 - error: ISO C++ forbids comparison between pointer and integer [-fpermissive] in a Lambda function ISO C ++禁止在C ++代码中比较指针和整数[-fpermissive] - ISO C++ forbids comparison between pointer and integer[-fpermissive] in C++ code ISO C++ 禁止比较指针和整数 [-fpermissive]| [C++] - ISO C++ forbids comparison between pointer and integer [-fpermissive]| [c++]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM