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; }

c/c++ 标准库 string的更多相关文章

  1. C++标准库string类型

    string类型支持长度可变的字符串,C++标准库将负责管理与存储字符相关的内存,以及提供各种有用的操作.标准库string类型的目的就是满足对字符串的一般应用. 本文地址:http://www.cn ...

  2. C++标准库<string>简单总结

    C++标准库<string>简单总结 在C++中,如果需要对字符串进行处理,那么它自带的标准库<string>无疑是最好的选择,它实现了很多常用的字符处理函数. 要想使用标准C ...

  3. C++标准库string

    C++标准库string 定义和初始化 string s1 默认初始化,s1是一个空串 string s2(s1) s2是s1的副本 string s2 = s1 等价于s2(s1),s2是s1的副本 ...

  4. 实现C++标准库string类的简单版本

    代码如下: #ifndef STRING_H #define STRING_H #include <cassert> #include <utility> #include & ...

  5. C 标准库 - string.h

    C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...

  6. 标准库string与C风格字符串

    返回字符串的长度 string标准库 #include<iostream> #include<cstring> using namespace std; int main() ...

  7. 【C++ Primer每日刷】之三 标准库 string 类型

    标准库 string 类型 string 类型支持长度可变的字符串.C++ 标准库将负责管理与存储字符相关的内存,以及提供各种实用的操作.标准库string 类型的目的就是满足对字符串的一般应用. 与 ...

  8. 把《c++ primer》读薄(3-1 标准库string类型初探)

    督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 问题1:养成一个好习惯,在头文件中只定义确实需要的东西 using namespace std; //建议需要什么再using声 ...

  9. C++ 标准库string字符串的截取

    标准库的string有一个substr函数用来截取子字符串.一般使用时传入两个参数,第一个是开始的坐标(第一个字符是0),第二个是截取的长度. #include <iostream> #i ...

随机推荐

  1. 为什么LINQ to XML的性能要优于XmlDocument?

    一直很忙,压了很多贴,今天发一篇吧.后面的看心情吧. 今天群里有人问如何解析web.config方便,然后我就推荐了Linq to XML,然后就有人说“我宁可XmlDocument,再SeleteN ...

  2. 不到50行代码实现一个能对请求并发数做限制的通用RequestDecorator

    使用场景 在开发中,我们可能会遇到一些对异步请求数做并发量限制的场景,比如说微信小程序的request并发最多为5个,又或者我们需要做一些批量处理的工作,可是我们又不想同时对服务器发出太多请求(可能会 ...

  3. 错误提示:The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project The type java.lang.Object cannot b

    原文:http://www.cnblogs.com/mmzs/p/7662863.html 错误类型: 搞了很久才找到原因.解决办法写出来分享: 出现以上错误的原因是玩耍maven时多装了个jre.本 ...

  4. LeetCode Animation 题目图解汇总(持续更新中...)

    我会尽力将LeetCode上所有的题目都用动画的形式演示出来,期待与你见证这一天! GitHub Repo:LeetCode Animation Follow: MisterBooo · GitHub ...

  5. 工作中常用Windows快捷键整理(1)-快速关闭网页

    打开桌面 win+D,显示桌面快捷键,不会关闭浏览器页面,是显示桌面. 关闭当前打开的所有标签页 Alt+F4,关闭当前打开的所有浏览器标签页. 关闭当前打开的标签页 Ctrl+W,关闭当前打开的标签 ...

  6. [转]node-sass 安装失败的各种坑

    本文转自:https://blog.csdn.net/weixin_42406046/article/details/80604623?tdsourcetag=s_pctim_aiomsg 版权声明: ...

  7. svn迁移后本地地址变更及externals无效的问题

    1.软件: visual SVN Server 2.具体方法: 在打开本地原来SVN check  out的根目录,点右键,tortoiseSVN --> relocate 弹出的对话框中修改s ...

  8. C# 只开启一个程序,如果第二次打开则自动将第一个程序显示到桌面

    using System; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.Int ...

  9. [日常] DNS解析概述

    DNS DomainNameSystem域名系统,根据域名查出IP地址 1.dig命令可以显示整个查询的过程 root@VM-38-204-ubuntu:~# dig www.sopans.com / ...

  10. windows10系统盘瘦身