+ 2
CHALLENGE: The variable name is entered from the keyboard. Determine if it is correct from the point of view of C ++?
The variable name is entered from the keyboard. Determine if it is correct from the point of view of C ++? The correct name of a variable can not begin with a digit, can not be longer than 256 characters, and does not contain special characters (except for '_') Code in C++
2 odpowiedzi
+ 5
Here's my attempt, this is good, teaches how to write valid variable names :)
https://code.sololearn.com/cYCc13sL2Kg1/?ref=app
+ 3
#include <iostream>
#include <regex>
using namespace std;
int main()
{
string var; getline(cin,var);
const regex pattern ("^[a-z_A-Z]\\w*quot;);
if(regex_match(var,pattern)&&var.length()<256)
cout<<"Yes, "<<var<<" is in accordance"
<<" with the C++ Rules.";
else
cout<<"No, "<<var
<<" has an incorrect syntax.";
}