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:
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.
Read More:
- error CS0234: The type or namespace name ‘UI‘ does not exist in the namespace ‘UnityEngine‘
- C + + common errors: “error: XXX in namespace ‘STD’ does not name a template type”
- Error resolution of ‘string’ does not name a type
- Error: global variable is ambiguous (conflict between using namespace STD and global variable)
- Caused by: java.net.SocketException : connection reset or caused by: java.sql.SQLRecoverableException solve
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- Converting string object into datetime type in pandas
- variable ‘std:ofstream’ has initializer but incomplete type
- Solution of flash screen caused by OpenGL in MFC environment
- Handling of expression not in group by key [value] reported by hive on October 12, 2020
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- Arduino reports an error when writing a custom library file to solve the problem of not name of type, not declared in this scope
- After introducing sass into Vue project, start to report error typeerror [err]_ INVALID_ ARG_ Type]: the “path” argument must be of type string
- Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- Solution to page scroll bar failure caused by opening secondary spring frame in Ant Design modal form
- android Caused by: java.util.ConcurrentModificationException
- Error message caused by browser plug-in
- The solution of flicker and no refresh caused by OpenGL + MFC
- “XXXXXX is a” namespace “, but here it is used as a” type “