为了账号安全,请及时绑定邮箱和手机立即绑定

std::string 与 #include<string>

std::string 与 #include<string>

墨色风雨 2018-08-10 10:09:27
#include "stdafx.h"#include <iostream>#include <string>using std::cout;using std::endl;using std::cin;using std::string;int main(void){    char chars1[20];    char chars2[20] = "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 0;}上面的程序如果没有#include<string>,则cin>>str1将会报错,而string str1不会报错也就是说在没有#include<string>的情况下,是可以定义std::string变量的,只是不能使用cin进行输入。 到底在没有头文件<string>的时候,std::string 是个什么东东,怎么理解?
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

那是因为对 string 的 >> 运算符重载是在 string 头文件中定义的;所以没有 string 头文件,就不能使用 >> 对 string 类型变量操作了


查看完整回答
反对 回复 2018-09-10
  • 1 回答
  • 0 关注
  • 775 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信