Tag Archives: summarize

Caused by the “error string in namespace std does not name a type” error

A weird thing happened when I was learning c++ today: when compiling the following code, the compiler displayed an 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 #include< string>

However, if you modify the code as shown below, you will also compile successfully.
The modified code is 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 this?
After Google, at http://www.cplusplus.com/ query to the ios libraries and other libraries relationship is as follows:

As you can see from the figure above, the StringStream library has been declared in the IoStream library and includes some of the string functionality. So that’s what happened.