小编vny*_*lng的帖子

C++用户输入限制,没有"goto"正确重试

我有以下代码:

qstn:
  cout << "Input customer's lastname: ";
  getline(cin, lname);

  if (lname.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ") != string::npos) {
      cout << "You can only input alpha here!\n";
      cin.clear();
      goto qstn;
  } else if (lname.empty()) {
      cout << "Please enter your firstname!\n";
      cin.clear();
      goto qstn;
  }

  int lnamel = lname.length();
  int strl = str.length();
  int is = 0;

  for (int i = 1; i < strl;) {
      i++;
      is++;

      if (lname[i] == lname[is] && lname[i] == ' ' || lname[0] == ' ') { …
Run Code Online (Sandbox Code Playgroud)

c++ validation iostream goto istream

2
推荐指数
1
解决办法
849
查看次数

标签 统计

c++ ×1

goto ×1

iostream ×1

istream ×1

validation ×1