當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::isalpha方法代碼示例

本文整理匯總了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;
}
開發者ID:JamesLinus,項目名稱:binspector,代碼行數:56,代碼來源:common.cpp

示例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;
}
開發者ID:flow-J,項目名稱:Exercise,代碼行數:14,代碼來源:ex3.22.cpp

示例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 << " + ";
  }
}
開發者ID:aManNamedTed,項目名稱:math,代碼行數:68,代碼來源:main.cpp

示例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;
}
開發者ID:Blurred-9L,項目名稱:BlurCC,代碼行數:99,代碼來源:Lexical.cpp

示例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;
}
開發者ID:ktjones,項目名稱:BVC2010,代碼行數:73,代碼來源:Soln8_08.cpp


注:本文中的std::isalpha方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。