#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. 【转】线程join()方法的含义

    在很多情况下,主线程生成并启动了子线程,如果子线程里要进行大量的耗时运算,主线程往往将于子线程之前结束,但是如果主线程处理完其它事务后,需要用到子线程的处理结果,也就是主线程需要等待子线程执行完成之后 ...

  2. LabVIEW将字符串转化为十进制

    (1)作用:将ASCII当做成十六进制来表示,并计算这个十六进制数对应的十进制大小 例如:008A本身对应的ASCII码用十六进制表示为为30 30 38 41,但有些协议中将008A当成0x008A ...

  3. php正则替换函数-----preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

    preg_replace — 执行一个正则表达式的搜索和替换 说明 mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $ ...

  4. atop工具检测linux硬件异常

    引言 Linux以其稳定性,越来越多地被用作服务器的操作系统(当然,有人会较真地说一句:Linux只是操作系统内核:).但使用了Linux作为底层的操作系统,是否我们就能保证我们的服务做到7*24地稳 ...

  5. 02 编程语言、python变量

    一 编程语言介绍(***) 1.1机器语言:直接用计算机能理解的二进制指令编写程序,直接控制硬件 优点:执行效率高,跨平台性低 缺点:开发效率低 1.2汇编语言:用英文标签取代二进制指令编写程序,本质 ...

  6. python-模块入门

    一.模块介绍 模块:模块就是一系列功能的集合体 模块有三种来源: 1.内置模块   2.第三方的模块   3.自定义模块 模块的格式: 1使用python编写的.py文件   2.已被编译为共享库或D ...

  7. Codeforces 671D Roads in Yusland [树形DP,线段树合并]

    洛谷 Codeforces 这是一个非正解,被正解暴踩,但它还是过了. 思路 首先很容易想到DP. 设\(dp_{x,i}\)表示\(x\)子树全部被覆盖,而且向上恰好延伸到\(dep=i\)的位置, ...

  8. vue入手

    https://www.jianshu.com/p/dc5057e7ad0d    (最全入坑教程) http://doc.liangxinghua.com/vue-family/1.4.html(v ...

  9. iOS 去除百度地图下方的 logo

    UIView *mView = _mapView.subviews.firstObject; for (id logoView in mView.subviews)  { if ([logoView  ...

  10. Java语法基础常见疑惑解答

    1. 类是java的最小单位,java的程序必须在类中才能运行 2. java函数加不加static有何不同 java中声明为static的方法称为静态方法或类方法.静态方法可以直接调用静态方法,访问 ...