Raised by "error string namespace STD does not name a type"

Source: Internet
Author: User

Learning C + + today encountered a strange phenomenon: when compiling the following code, the compiler displays the error:

Error: ' String ' in namespace ' std ' does not name a type

The procedure is as follows:

struct Sales_data
{
	std::string bookno;
	std::string bookname;
	unsigned int count;
	Double price;
};
int main ()
{return
	0;
}

Obviously, there is a lack of a #include<string>

However, if you modify the code as shown below, you can also compile successfully.

Modify the code as follows:

#include <iostream>
struct sales_data
{
	std::string bookno;
	std::string bookname;
	unsigned int count;
	Double price;
};
int main ()
{return
	0;
}


What is the reason for that?

Google, on the http://www.cplusplus.com/Web site to query the iOS library and other libraries have the following relationship:

From the image above you can see that the StringStream Library has been declared in the iostream library, and contains some of the functions of string. So there was this phenomenon.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.