// assertQQ.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; long assertQQ(string str) { int length = str.length(); //判断长度 if (length <5 || length >10) { return 0; } //排头字母是0-3 char* a =(char*)( str.c_str()); if (a[0] <49 && a[0] >51) { return 0; } //全是数字 for (int i=0; i<length; i++) { if (a[i] < 48 ||a[i] >57)// 48 .57 是 0 9 的ascall码 { return 0; } } return atoi(a); } int main(int argc, char* argv[]) { printf("please input your QQ number: /n"); string str; cin>>str; //判断 long QQ = assertQQ(str); if (QQ ==0) { cout<<"QQ is invalid !"<<endl; } else { cout<<"QQ number :"<<QQ<<endl; } return 0; } //? long是 32 还是64?