赞
踩
今天学习c++时遇到一个诡异的现象:当编译如下代码时编译器显示错误为:
error: 'string' in namespace 'std' does not name a type
程序如下:
- struct sales_data
- {
- std::string bookNo;
- std::string bookName;
- unsigned int count;
- double price;
- };
- int main()
- {
- return 0;
- }
但是,如果修改代码如下所示的话,同样也能编译成功。
修改代码如下:
- #include<iostream>
- struct sales_data
- {
- std::string bookNo;
- std::string bookName;
- unsigned int count;
- double price;
- };
- int main()
- {
- return 0;
- }
经过google,在http://www.cplusplus.com/ 网站上查询到ios库与其他库的关系如下:
从上图可以看到iostream库里已经声明了stringstream库,包含了string的部分功能。所以出现了如此现象。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。