我有这个奇怪的代码问题。在视觉工作室中,我所有的'cout','cin'和'我的'系统都有红色的波形,并被标记为不明确的代码。该项目仍然编译好,并没有给我任何错误或警告,但它是讨厌的,并会阻止我知道什么时候我犯了一个实际的错误。当我添加'if(argc> 0)'部分并且如果我删除它,然后删除并重新键入'using namespace std;',所有这一切都开始了。波浪消失。不幸的是,当我重新输入上面的'if'语句时,问题就会返回。我真的很感谢一些帮助。 谢谢大家!Visual Studio在添加if语句后显示C++歧义错误
#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)'实际上将0赋给'argc',然后转换为一个bool表达式为'false',并且没有任何东西会在分支中执行(这是大部分发布的代码)。此外,'argc'包含计数中的程序名称,所以它应该始终至少为1. – SleuthEye 2014-09-30 01:36:37
'argc'将[通常不会为零](http://stackoverflow.com/questions/8113786/executing-a- process-with-argc-0)用于从普通桌面计算环境的命令行启动的应用程序。 'argv [0]'指针通常指向一个字符串,它是启动的应用程序的名称。 “命令行参数”通常位于'argv [1]'和后面的位置。 – 2014-09-30 01:44:24
改变标题/标签,如果它真的*“视觉学生”。 – user2864740 2014-09-30 02:03:26