std::string 是什么
#include "stdafx.h"
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main(void)
{
char chars1[];
char chars2[] = "jaguar";
string str1;
string str2 = "pather";
cout << "Enter a kind of feline: " << endl;
cin >> chars1;
cout << "Enter another kind of feline: " << endl;
cin >> str1;
cin.get();
return ;
}
上面的程序如果没有#include<string>,则cin>>str1将会报错,而string str1不会报错,那么std::string是在哪里定义的?
头文件之间的包含关系如下
#include <iostream>
#include <istream>
#include <ostream>
#include <ios>
#include <xlocnum>
#include <cstdio>
#include <yvals.h>
在iostream里,使用了宏_STD_BEGIN,该宏是定义在yvals.h里的

但是这里面却没有找到string的定义,后来发现std::string是定义在<xstring>里
#include <iostream>
#include <istream>
#include <ostream>
#include <ios>
#include <xlocnum>
#include <streambuf>
#include <xiosbase>
#include <system_error>
#include <stdexcept>
#include <xstring>

<xstring>通过引用#include <xmemory0>,间接又引用了yvals.h,得以使用_STD_BEGIN宏,将许多类型加入到命名空间std,其中就包括了string

std::string 是什么的更多相关文章
- QString 和std::string互转
std::string cstr; QString qstring; //****从std::string 到QString qstring = QString(QString::fromLocal8 ...
- std::string的split函数
刚刚要找个按空格分离std::string的函数, 结果发现了stackoverflow上的这个问题. 也没仔细看, 直接拿来一试, 靠, 不对啊, 怎么分离后多出个空字符串, 也就是 "a ...
- could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
VS2008, 写一个简单的demo的时候出现了这个: 1>------ Build started: Project: GetExportTable, Configuration: Relea ...
- 源码阅读笔记 - 3 std::string 与 Short String Optimization
众所周知,大部分情况下,操作一个自动(栈)变量的速度是比操作一个堆上的值的速度快的.然而,栈数组的大小是在编译时确定的(不要说 C99 的VLA,那货的 sizeof 是运行时计算的),但是堆数组的大 ...
- CString std::string相互转换
CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); s ...
- 计算std:string的字节长度
如果项目本身是使用 Unicode 字符集和utf8编码,std::string的length(),size()甚至是c的strLen取到的都是字节长度了,比如三个汉字,就是9, 以上情况不满足的话, ...
- 【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
今天遇到一个非常难以排查的BUG,谷歌度娘都问过了依旧无解,最后自己重新尝试之后找到解决方案: 先看一下报错信息: 1>.\lenz.cpp(2197) error C2679: binary ...
- 类型安全且自动管理内存的返回 std::string 的 sprintf 实现
在这篇博文里,我提到了一个例子,说的是使用C++实现类型安全的printf.这个例子很惊艳,但是在我写程序的时候,并非那么"迫切"地需要它出现在我的工具箱中,因为它并不比普通的pr ...
- VC++ 中使用 std::string 转换字符串编码
目录 第1章说明 1 1.1 代码 1 1.2 使用 4 第1章说明 VC++中宽窄字符串的相互转换比较麻烦,借助std::string能大大减少代码量. 1.1 代码 函数声明如下 ...
- std::string::npos mean
std::string::npos 表示 no position, 没位置, 没找到
随机推荐
- SQL Server异常汇总
1.特定用户名无法访问数据库 例如需要使用sa用户名访问School数据库失败,提示如下: (你要设置的)数据库--属性--文件--所用者设为Sa,回到用户映射查看,已勾选上. 还有一些情况 1)将登 ...
- 前端-----JavaScript 初识基础
JavaScript的组成 JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for语句等. DOM:操作网页上的 ...
- 前端----css 选择器
css 为了修饰页面作用, 让页面好看 ⑴ css的引入方式1,行内样式body里面2,内接样式在html里面的 style 里面3,外接样式两种:①链接式: <link rel=" ...
- Ex 2_25 n位十进制整数转换为二进制形式..._第四次作业
(a) 当n=1时,(10)d=(1010)b 当n=2时,(100)d=(10)d x (10)d=(1010)b x (1010)b 当n=4时,(10000)d=(100)d x (100) ...
- linux计算服务器最近一次重启的时间
date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S" 这 ...
- python-进程池与线程池,协程
一.进程池与线程池 实现并发的手段有两种,多线程和多进程.注:并发是指多个任务看起来是同时运行的.主要是切换+保存状态. 当我们需要执行的并发任务大于cpu的核数时,我们需要知道一个操作系统不能无限的 ...
- 洛谷P4389 付公主的背包 [生成函数,NTT]
传送门 同样是回过头来发现不会做了,要加深一下记忆. 思路 只要听说过生成函数的人相信第一眼都可以想到生成函数. 所以我们要求 \[ ans=\prod \sum_n x^{nV}=\prod \fr ...
- Vue-tab选项卡
<div id='test'> <ul class="nav" > <li v-for='(item,index) in dataNav' @clic ...
- 练就Java24章真经—你所不知道的工厂方法
前言 最近一直在Java方向奋斗<终于,我还是下决心学Java后台了>,今天抽空开始学习Java的设计模式了.计划有时间就去学习,你这么有时间,还不来一起上车吗? 之所以要学习Java模式 ...
- SWift中 '?' must be followed by a call, member lookup, or subscript 错误解决方案
那是因为你在使用自己写的分类时没有指定返回的数据类型 指定下返回数据类型就好了 我是用的oc写的分类在Swift中使用的 错误代码 private lazy var btn = UIButton.C ...