#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不会报错,那么std::string是在哪里定义的?
头文件之间的包含关系如下
#include <iostream>
#include <istream>
#include <ostream>
#include <ios>
#include <xlocnum>
#include <cstdio>
#include <yvals.h>
在iostream里,使用了宏_STD_BEGIN,该宏是定义在yvals.h里的
原文地址:https://www.cnblogs.com/heben/p/9383704.html
时间: 2024-10-24 16:52:02