#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 是什么的更多相关文章

  1. QString 和std::string互转

    std::string cstr; QString qstring; //****从std::string 到QString qstring = QString(QString::fromLocal8 ...

  2. std::string的split函数

    刚刚要找个按空格分离std::string的函数, 结果发现了stackoverflow上的这个问题. 也没仔细看, 直接拿来一试, 靠, 不对啊, 怎么分离后多出个空字符串, 也就是 "a ...

  3. could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'

    VS2008, 写一个简单的demo的时候出现了这个: 1>------ Build started: Project: GetExportTable, Configuration: Relea ...

  4. 源码阅读笔记 - 3 std::string 与 Short String Optimization

    众所周知,大部分情况下,操作一个自动(栈)变量的速度是比操作一个堆上的值的速度快的.然而,栈数组的大小是在编译时确定的(不要说 C99 的VLA,那货的 sizeof 是运行时计算的),但是堆数组的大 ...

  5. CString std::string相互转换

    CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); s ...

  6. 计算std:string的字节长度

    如果项目本身是使用 Unicode 字符集和utf8编码,std::string的length(),size()甚至是c的strLen取到的都是字节长度了,比如三个汉字,就是9, 以上情况不满足的话, ...

  7. 【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'

    今天遇到一个非常难以排查的BUG,谷歌度娘都问过了依旧无解,最后自己重新尝试之后找到解决方案: 先看一下报错信息: 1>.\lenz.cpp(2197)  error C2679: binary ...

  8. 类型安全且自动管理内存的返回 std::string 的 sprintf 实现

    在这篇博文里,我提到了一个例子,说的是使用C++实现类型安全的printf.这个例子很惊艳,但是在我写程序的时候,并非那么"迫切"地需要它出现在我的工具箱中,因为它并不比普通的pr ...

  9. VC++ 中使用 std::string 转换字符串编码

    目录 第1章说明    1 1.1 代码    1 1.2 使用    4 第1章说明 VC++中宽窄字符串的相互转换比较麻烦,借助std::string能大大减少代码量. 1.1 代码 函数声明如下 ...

  10. std::string::npos mean

    std::string::npos 表示 no position, 没位置, 没找到

随机推荐

  1. js加密转python3

    //add by wangp at 2018-01-23 密码加密方法 start function encrypt(pwd){ var key = "MIIBIjANBgkqhkiG9w0 ...

  2. python3+selenium框架设计06-编写POM测试用例

    之前我们已经把测试基类,配置文件操作,浏览器引擎类封装完成.接下来使用POM的设计思路来创建我们的测试用例.接下来看一个实例,先在项目下新建pageobject文件夹.这个文件夹下放所有要测试的页面类 ...

  3. WINDOWS系统中常用网络命令及命令实例详解

    一.查询DNS.IP,mac地址及DHCP服务的情况 二.查看ARP表:MAC地址与IP地址的映射表 三.查看共享资源 四.查看局域网内的主机名 五.查看用户列表  六.路由跟踪命令 七.查看共享资源 ...

  4. 第八章 让Bootstrap轮播插件carousel支持左右滑动手势的三种方法

    因为最近开发的项目涉及到移动设备上的 HTML5 开发,其中需要实现轮播效果.然后最快捷的方式,你知道的(Bootstrap),然后原生的 Bootstrap 的 carousel.js 插件并没有支 ...

  5. centos6.5环境wget报错Unable to establish SSL connection

    centos6.5环境wget报错Unable to establish SSL connection [root@centossz008 src]# wget --no-check-certific ...

  6. jquery日常使用总结

    1.如何跳出each循环 用 return false, 不是 break. $.each(resArray, function(j, n) { if (1 == n) { return false; ...

  7. 压缩JS的eclipse插件

    主页:http://jscompressor.oncereply.me/ Update site: http://jscompressor.oncereply.me/update/

  8. ebs 12.1.1升级到12.1.3

    升级过程参考 Oracle电子商务套件版本12.1.3自述文件 (文档 ID 1534411.1) 应用启动到维护模式 adadmin 打以下patch 9239089  9239090  92390 ...

  9. web网页测试用例(非常实用)

    转自:http://blog.csdn.net/yuki_ying/article/details/54946541 一.Web测试中,各类web控件测试点总结 一 .界面检查 进入一个页面测试,首先 ...

  10. 前端 ----关于DOM的事件操作

    关于DOM的事件操作   一.JavaScript的组成 JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for ...