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. SpringMVC跨域问题排查以及源码实现

    SpringMVC跨域问题排查以及源码实现 最近一次项目中,将SpringMVC版本从4.1.1升级到4.3.10,出现跨域失败的情况.关于同源策略和跨域解决方案,网上有很多资料. 项目采用的方式是通 ...

  2. 一篇文章让你成为 NIO 大师 - MyCAT通信模型

    这篇文章没有详细介绍 NIO 的概念,对于 NIO 不了解的同学,可根据自己需要,阅读这篇介绍 NIO 的博客    io.mycat.net.NIOAcceptor NIOAcceptor负责处理客 ...

  3. .NET ThreadPool算法

    .NET ThreadPool相关算法记录 1.ManagedThreadPool (corefx) .net4.0之前只有全局队列,为了解决全局队列多线程竞争使用问题,引入work-stealing ...

  4. GVRP 的工作机制和工作模式

    GVRP 简介 GVRP 基于 GARP 的工作机制来维护设备中的 VLAN 动态注册信息,并将该信息向其他设备传播:当设备启动了 GVRP 之后,就能够接收来自其他设备的 VLAN 注册信息,并动态 ...

  5. Video for Linux Two API Specification

    V4L2 的使用规范,网址为:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.ht ...

  6. 【原】KMeans与深度学习自编码AutoEncoder结合提高聚类效果

    这几天在做用户画像,特征是用户的消费商品的消费金额,原始数据(部分)是这样的: id goods_name goods_amount 男士手袋 1882.0 淑女装 2491.0 女士手袋 345.0 ...

  7. 隐藏马尔科夫模型HMM

    概率图模型 HMM 先从一个具体的例子入手,看看我们要解决的实际问题.例子引自wiki.https://en.wikipedia.org/wiki/Hidden_Markov_model Consid ...

  8. Layui table 组件的使用:初始化加载数据、数据刷新表格、传参数

    背景 笔者之前一直使用 bootstrap table ,因为当前项目中主要使用 Layui 框架,于是也就随了 Layui table ,只是在使用的时候出现了一些问题,当然也是怪自己不熟悉的锅吧! ...

  9. 验证码图片二值化问题 BitmapData 怎么解决

    对不起,这算是一篇求助啦,先上图,防止不清楚,放大了一点,下面是图片,上面是没有二值化的,下面是二值化之后的,我其实不懂什么是二值化啦,就是一定范围变黑,变白 问题: 为什么我的结果上面还是有很多彩色 ...

  10. java安全管理器SecurityManager介绍

    java安全管理器类SecurityManager简单剖析: javadoc介绍: SecurityManager是一个允许应用实现一种安全策略的类.它允许一个应用去明确,在执行一个可能安全或者敏感的 ...