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.