c++ - Visual Studio 在添加 if 语句后显示 C++ 歧义错误

标签 c++ visual-studio ambiguous

我遇到了这个奇怪的代码问题。在 visual studio 中,我所有的“cout”、“cin”和“system”都有红色波浪线,并被标记为不明确的代码。该项目仍然可以正常编译并且不会给我任何错误或警告,但这很烦人并且会阻止我知道我何时犯了实际错误。当我添加“if(argc > 0)”部分时,这一切都开始了,如果我删除它,然后删除并重新键入“using namespace std;”曲线消失了。遗憾的是,当我重新输入上面的“if”语句时,问题又来了。我真的很感激一些帮助。 谢谢大家!

#include <string>
#include <iostream>
#include "chkString.h"
using namespace std;

int main(int argc, char * argv){
    int cipher;
    int encryption;
    string keyPhrase;
    string iFile;
    string oFile;
    chkString chk;
    cout << "Hello User!" << endl;
    if(argc > 0){
        cout << "Hello";
    }
    if(argc = 0){
        cout << "Enter '1' for Vigenere, or '2' for Playfair, or '0' to quit: ";
        cin >> cipher;

        while(cipher != 1 && cipher != 2 && cipher != 0){
            cout << "I'm sorry that is not a valid entry. "
                << "Please retry." << endl <<
                "Enter '1' for Vigenere, or '2' for Playfair, or '0' to quit: ";
            cin >> cipher;
        }
        if(cipher == 0){
            return 0;
        }

        cout << "Enter '1' for encryption, '2' for decryption: ";
        cin >> encryption;

        while(encryption != 1 && encryption != 2){
            cout << "I'm sorry that is not a valid entry. "
                << "Please retry." << endl <<
                "Enter '1' for encryption, '2' for decryption: ";
            cin >> encryption;
        }

        cout << "Enter the keyphrase: ";
        cin >> keyPhrase;

        while(!(chk.intCheck(keyPhrase))){
            cout << "I'm sorry that is not a valid entry. "
                    << "Please retry." << endl << "Enter keyphrase: ";
                cin >> keyPhrase;
        }

        cout << "Enter your output file name: ";
        cin >> oFile;

        cout << "Enter yout input file name: ";
        cin >> iFile;
    }
    cout << "Hello" << endl;
    system("pause");
    return 0;
}

最佳答案

很明显,大部分程序都不会执行,因为:

if(argc = 0){
// ...
}

assigns 0 给 argc 然后测试 false,因为 argc 现在是 0,所以代码块永远不会执行。

关于c++ - Visual Studio 在添加 if 语句后显示 C++ 歧义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26111407/

相关文章:

c++ - 临时数据成员的生命周期延长和API设计

c++ - sscanf 到 stringstream 转换

visual-studio-2010 - 如果我想在同一个工作区中复制我的 c# 项目,我该怎么做?

c++ - 策略模式 Qt 模糊基础

java - 使用 cygwin 为 JNI (Android NDK) 编译 C++ 代码

c++ - 从具有基类 ptr 的 vector 中删除

c - 如何在没有visual studio的情况下编译C文件

c++ - 识别 Visual Studio 中的重载运算符 (c++)

c++ - 继承问题 "ambiguous request"

c++ - 退出时覆盖不明确的函数时代码如何运行?