设为首页 加入收藏

TOP

c/c++ 标准库 string
2018-10-21 16:08:48 】 浏览:38
Tags:c/c 标准 string

c/c++ 标准库 string

标准库 string的小例子
test1~test10

#include <iostream>

using namespace std;

int main(void){
  //test1                                                                      
  //string s1,s2;                                                              
  //cin >> s1 >> s2;                                                           
  //cout << s1 << ";" << s2 << endl;                                           

  //test2                                                                      
  //string wd;                                                                 
  //while(cin >> wd){                                                          
  //  cout << wd << endl;                                                      
  //}                                                                          

  //test3                                                                      
  /*                                                                           
  string line;                                                                 
  while(getline(cin, line)){                                                   
    cout << line << endl;     
  }                                                                            
  */
  //test4                                                                      
  /*                                                                           
  string line;                                                                 
  while(getline(cin, line)){                                                   
    if(!line.empty()){                                                         
      cout << line << endl;                                                    
    }                                                                          
    else{                                                                      
      cout << "empty" << endl;                                                 
    }                                                                          
  }                                                                            
  */

  //test5                                                                      
  /*                                                                           
  string line;                                                                 
  while(getline(cin, line)){                                                   
    if(line.size() > 2){                                                       
      cout << line << endl;                                                    
    }                                                                          
  }        string::size_type len = string("1111111111111111abc").size();                
  cout << len << endl;                                                         
  int n = -1;                
  //注意,如果n为负值,不管 len为多大的字符串,下面的条件都是真。
  //因为,编译器会把负值n转化为一个特别大的正数。
  if(len < n){                                                                 
    cout << "in" << endl;                                                      
  }                                                                            
  */

  //test6                                                                      
  /*                                                                           
  string s("asdfdsf!!!");                                                      
  decltype(s.size()) cnt = 0;                                                  
  for(auto c : s){                                                             
    if(ispunct(c))                                                             
      ++cnt;                                                                   
  }                                                                            
  cout << cnt << "times" << endl;                                              
  */

  //test7                                                                      
  /*                                                                           
  string s("aaasd!!!");                                                        
  for(auto& c : s){                                                            
    c = toupper(c);                                                            
  }                                                                            
  cout << s << endl;                                                           
  */

  //test8                                                                      
  /*                                                                           
  string s("abc def");                                                         
  if(!s.empty())                                                               
    s[0] = toupper(s[0]);                                                      
  cout << s << endl;                                                           
  */

  //test9                                                                      
  /*                                                                           
  string s("one two");                                                         
  for(decltype(s.size()) idx = 0;                                              
      idx != s.size() && !isspace(s[idx]); ++idx){                             
    s[idx] = toupper(s[idx]);                                                  
  }                                                                            
  cout << s << endl;                                                           
  */

  //test10                                                                     
  const string hex("0123456789ABCDEF");
  string result;
  string::size_type n;
  while(cin >> n){
    if(n < hex.size()){
      result += hex[n];
    }
  }
  cout << result << endl;

}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇StretchBlt函数和BitBlt函数的区.. 下一篇[牛客OI测试赛2]F假的数学游戏(斯..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目