我如何编写程序代码来查看程序的索引7,只读取此代码最后一部分的两个字母中的一个。我是新人,并且已经有一段时间了。这给了我一个艰难的时间,我继续阅读这本书并下载一些视频,但我似乎没有得到这个。
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string string;
// get character
cout << "\nEnter Email address ID: ";
getline(cin, string );
cout << endl;
{
if (!isalpha(string[0]))
cout << "first charactor needs to be a Letter"<< endl;
if (!isalpha(string[1]))
cout << "Second charactor needs to be a letter"<< endl;
if (!isdigit(string[2]))
cout << "Third charactor needs to be a number"<< endl;
if (!isdigit(string[3]))
cout << "Fourth charactor needs to be a number"<< endl;
if (!isdigit(string[4]))
cout << "Fifth charactor needs to be a number"<< endl;
if (!isdigit(string[5]))
cout << "Sixth charactor needs to be a number"<< endl;
if (!isdigit(string[6]))
cout << "Seventh charactor needs to be a number"<< endl;
if(!isalpha(string[7]))
if(string != "n" || string !="p")
cout << "Eight charactor needs to be a N or P"<< endl;
{
}
cout << endl;
system("pause");
return 0;
}
}
答案 0 :(得分:2)
- &gt; IsAlpha确定整数是否表示字母字符 输出:
Enter Email address ID: abcdef1@kmail.com
Third charactor needs to be a number
Fourth charactor needs to be a number
Fifth charactor needs to be a number
Sixth charactor needs to be a number
Eight charactor needs to be a N or P
Press any key to continue . . .
// -----------------------如下所示更改大括号------
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string string;
// get character
cout << "\nEnter Email address ID: ";
getline(cin, string );
cout << endl;
{
if (!isalpha(string[0]))
cout << "first charactor needs to be a Letter"<< endl;
if (!isalpha(string[1]))
cout << "Second charactor needs to be a letter"<< endl;
if (!isdigit(string[2]))
cout << "Third charactor needs to be a number"<< endl;
if (!isdigit(string[3]))
cout << "Fourth charactor needs to be a number"<< endl;
if (!isdigit(string[4]))
cout << "Fifth charactor needs to be a number"<< endl;
if (!isdigit(string[5]))
cout << "Sixth charactor needs to be a number"<< endl;
if (!isdigit(string[6]))
cout << "Seventh charactor needs to be a number"<< endl;
if(!isalpha(string[7]))
{
if(string != "n" || string !="p")
{cout << "Eight charactor needs to be a N or P"<< endl;
}
}
cout << endl;
system("pause");
return 0;
}
}