C++验证有疑问

Ner*_*era 0 c++ validation

#include<iostream>
using namespace std;

void main()
{

    char fname[11]; 
    int x = 0; 

    cout << "Please enter the name: "; 
    cin >> fname;

    while (fname[x] != '\0') 
    { 
        int i=int(fname[x]);
        if (i>=97)
            cout << fname[x]; 
        x++; 
    } 

    else    
        cout << "Invalid characters";

    system("pause");
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用上面的代码验证char输入.但是做不到.

这些代码有什么问题?

Kos*_*Kos 6

  • 用C++ int main代替void main,
  • 你应该使用std::string而不是char数组(更安全,更方便),
  • 为了测试单个字符是否为字母,有一些函数<cctype>,例如isalpha(),
  • 如果没有"if",你就不能拥有"其他".

尝试绘制您想要实现的流程图.