我的代碼包含一個If Else語句。我希望它來驗證用戶輸入付諸腳本上兩件事情的字符串:C++ If Else語句問題
- 字符串的長度必須大於0
- 字符串必須包括字母字符
下面是我的代碼,我認爲錯誤是用字符串代碼長度做的。
編輯之前:
cout << "Your word: " << szOriginal << "\n";
if szOriginal.length() > 0 and (isalpha(szOriginal))
{
szWord = szOriginal.tolower();
cout << szWord << "\n";
}
else
{
cout << "Please enter a valid word." << endl;
}
對不起球員,通過開發 - C產生++誤差
預期 '(' 「szOriginal」
鏈接到PRINTSCREEN之前:http://gyazo.com/b3f43928072e9c2a5a8a712a9030364d
用變量聲明編輯後d例如:
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
string original;
cout << "Welcome to the English to Pig Latin translator!\n";
cout << "Type a word you wish to translate:\n";
cin >> original;
cout << "Your word: " << original << "\n";
if (original.length() > 0 && (isalpha(original)))
{
word = original.tolower();
cout << Word << "\n";
}
else
{
cout << "Please enter a valid word." << endl;
}
system("PAUSE");
return 0;
}
對不起,這個壞的帖子!
產生[SSCCE](http://sscce.org)併發布完整的錯誤。 – chris
什麼錯誤?你是否真的錯過了'if'子句中的'()'? – crashmstr
什麼是「錯誤」? – tadman