本文整理汇总了C++中std::isalpha方法的典型用法代码示例。如果您正苦于以下问题:C++ std::isalpha方法的具体用法?C++ std::isalpha怎么用?C++ std::isalpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::isalpha方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: build_path
std::string build_path(const_inspection_branch_t main, const_inspection_branch_t current)
{
#if !BOOST_WINDOWS
using std::isalpha;
#endif
std::vector<std::string> result_set;
result_set.reserve(10);
while (true)
{
std::string path_segment;
bool is_array_element(current->get_flag(is_array_element_k));
if (is_array_element)
{
boost::uint64_t index(node_value(current, ARRAY_ELEMENT_VALUE_INDEX));
// REVISIT (fbrereto) : String concatenation here.
path_segment += "[" + boost::lexical_cast<std::string>(index) + "]";
}
else
{
adobe::name_t name(node_property(current, NODE_PROPERTY_NAME));
if (name)
path_segment = name.c_str();
}
if (!path_segment.empty())
result_set.push_back(path_segment);
current.edge() = adobe::forest_leading_edge;
if (current == main)
break;
current = adobe::find_parent(current);
}
std::string result;
bool first(true);
for (std::vector<std::string>::reverse_iterator iter(result_set.rbegin()), last(result_set.rend()); iter != last; ++iter)
{
if (!first && isalpha((*iter)[0]))
result += ".";
result += *iter;
first = false;
}
return result;
}
示例2: main
int main()
{
vector<string> text;
for(string line; getline(cin, line); text.push_back(line));
for (auto &word : text)
{
for (auto &ch : word)
if (isalpha(ch)) ch = toupper(ch);
cout << word << endl;
}
return 0;
}
示例3: pascals_triangle
void pascals_triangle()
{
//to catch the return from main
cin.ignore(1, '\n');
string response;
string input;
int power = 0;
int a = 0;
int b = 0;
char c;
char x = 'x';
char y = 'y';
cout << "Enter your expression for Pascal's Triangle." << endl;
getline(cin, response);
for(int i = 0; i < response.size(); i++)
{
if(response[i] != ' ')
{
input += response[i];
}
}
for(int i = 0; i < input.size(); i++)
{
if(isalpha(input[i]))
{
cout << input[i];
}
else if(isoperation(input[i]))
{
cout << input[i] << " is an operation";
}
else if(input[i] == '^')
{
power = static_cast<int>(input[i+1] - 48);
cout << power << " is the power";
}
cout << endl;
}
//assign a and b values,
a = b = 1;
//assign x and y values.
for(int i = 0; i < power+1; i++)
{
if(i == 0)
{
cout << x << "^" << power;
}
else if(i == 1)
{
cout << power << x << y << "^" << power-1;
}
else if(i == 2)
{
cout << power << x << "^" << power-1 << y;
}
else if(i == 3)
{
cout << y << "^" << power;
}
cout << " + ";
}
}
示例4: nextState
int Lexical::nextState( int curState, char input ){
// L, D, ", \, ., +, -, *, /, >, <, !, =, &, |, {, }, (, ),',', ;
int transitions[STATES][INPUTS] = { { 1, 2, 5, -1, 4, 8, 8, 9, 9, 10, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22},
{ 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, 2, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{ 5, 5, 7, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} };
int next = -1;
switch( input ){
case '.':
next = transitions[curState][POINT];
break;
case '\\':
next = transitions[curState][BACKSLASH];
break;
case '\"':
next = transitions[curState][D_QUOTE];
break;
case '+':
next = transitions[curState][PLUS];
break;
case '-':
next = transitions[curState][MINUS];
break;
case '*':
next = transitions[curState][PROD];
break;
case '/':
next = transitions[curState][DIV];
break;
case '>':
next = transitions[curState][GREATER];
break;
case '<':
next = transitions[curState][LESSER];
break;
case '!':
next = transitions[curState][NOT];
break;
case '=':
next = transitions[curState][EQ];
break;
case '&':
next = transitions[curState][AND];
break;
case '|':
next = transitions[curState][OR];
break;
case '{':
next = transitions[curState][LCB];
break;
case '}':
next = transitions[curState][RCB];
break;
case '(':
next = transitions[curState][LP];
break;
case ')':
next = transitions[curState][RP];
break;
case ',':
next = transitions[curState][COMMA];
break;
case ';':
next = transitions[curState][SEMI_COLON];
default:
if( isalpha( input ) or input == '_' ){
next = transitions[curState][LETTER];
}
else if( isdigit( input ) ){
next = transitions[curState][DIGIT];
}
else if( curState == 5 || curState == 6 ){
next = 5;
}
break;
}
return next;
}
示例5: main
int main() {
string text; // The string to be searched
const size_t maxwords(100); // Maximum number of words to be changed
string words[maxwords]; // Words to be changed
size_t wordcount(0); // Actual number of words to be changed
cout << "Enter the text that is to be searched terminated by #:" << endl;
std::getline(cin, text, '#');
string textcopy(text); // Make a copy of the string
// Convert copy to lowercase
for(size_t i = 0 ; i<textcopy.length() ; i++)
textcopy[i] = tolower(textcopy[i]);
while(true)
{
cout << "Enter a word that is to be replaced in the string or enter # to end: ";
cin >> words[wordcount];
if(words[wordcount] == "#")
break;
if(++wordcount == maxwords)
{
cout << endl << "Maximum number of words reached." << endl;
break;
}
}
for(size_t i = 0 ; i<wordcount ; i++)
{
string wordcopy = words[i]; // Make a copy of the word
// Convert copy to lowercase
for(size_t j = 0 ; j<wordcopy.length() ; j++)
wordcopy[j] = tolower(wordcopy[j]);
// Create string with the same number of asterisks as there are in word
string asterisks(wordcopy.length(), '*');
cout << endl << "Each occurrence of \"" << words[i]
<< "\" will be replaced by " << asterisks << "." << endl;
// Search for wordcopy within textcopy object
// but replace by asterisks in text
size_t position = 0;
while((position = textcopy.find(wordcopy, position)) != string::npos)
{
// We have to check that the characters before and after the word found
// are not alphabetic, but we need to take care not to use index values
// that are illegal - hence all the ifs.
if(position==0)
{ // We are at the beginning of the text
if(position+wordcopy.length()==text.length()) // Check for 1 past the word being the end of the text
text.replace(position, wordcopy.length(), asterisks); // Replace word
else if (!isalpha(textcopy[position+wordcopy.length()])) // Check for 1 past the word not being alphabetic
text.replace(position, wordcopy.length(), asterisks); // Replace word
}
else if(!isalpha(textcopy[position-1]))
{
if(position+wordcopy.length()==text.length()) // Check for 1 past the word being the end of the text
text.replace(position, wordcopy.length(), asterisks); // Replace word
else if (!isalpha(textcopy[position+wordcopy.length()])) // Check for 1 past the word not being alphabetic
text.replace(position, wordcopy.length(), asterisks); // Replace word
}
position += wordcopy.length();
}
cout << endl << "After processing the original string is now:" << endl
<< text << endl;
}
cout << endl << "All substitutions have been made." << endl;
return 0;
}