gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:51 25 4
gpt4 key购买 nike

我遇到了这个奇怪的代码问题。在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com