我遇到了这个奇怪的代码问题。在视觉工作室中,我所有的'cout','cin'和我的'系统'都有红色曲线,并被标记为含糊不清的代码。该项目仍然编译好,并没有给我任何错误或警告,但它很烦人,将阻止我知道我何时犯了一个实际的错误。这一切都是在我添加'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;
}
答案 0 :(得分:4)
很明显,大部分程序都不会被执行,因为:
if(argc = 0){
// ...
}
将 0分配给argc
,然后测试为false,因为argc
现在是0
,因此代码块永远不会被执行。
答案 1 :(得分:3)
您有错误:
if(argc = 0){ // should be ==
不是编译错误,而是逻辑错误。可能是因为它导致Visual Studio代码分析意识到你在说:
if(0) {
永远不会成立,因此代码分析器知道该块无法执行。