错误的 STL 标头
我想制作一些 STL 集,但是当我这样做时,它告诉我
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
,这意味着我没有包含正确的标头定义 (#define
),但我已经包含了。集合是否位于不同的位置?源代码看起来像这样
set<int> playerlist;
头文件是...
#include <iostream>
//#include "winsock2.h"
#include "Ws2tcpip.h"
#include <list>
//#include <windows.h>
#include <process.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <map>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
#include <set>
I want to make some STL sets but when I do it tells me
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
Meaning I have not included the proper header define (#define <set>
) but I have. Are sets just under a different location? The source looks like this
set<int> playerlist;
The header files are...
#include <iostream>
//#include "winsock2.h"
#include "Ws2tcpip.h"
#include <list>
//#include <windows.h>
#include <process.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <map>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
#include <set>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要的是
而不是
在使用该集合之前在 main 函数之前写入以下行
What you need is
and not
also before using the set write the following line before your main function
我
希望你的意思是
?
您还需要以某种方式表明您想要来自
std
命名空间的set
。您可以通过在引用set
的所有地方添加std::
前缀来实现这一点:或者使用
using
声明告诉编译器每当您引用set
时,您的意思是std::set
:(也可以编写一个包罗万象的
using namespace std;
声明这说明你总是想使用来自std
命名空间,但这通常被认为是不好的做法,我提到它只是因为,尽管这是不好的做法,但它相当常见,所以您很可能会遇到这样做的代码。)By
I hope you mean
?
You also need to indicate somehow that you want the
set
from thestd
namespace. You can do that either by prefixingset
withstd::
everywhere that you refer to it:or by using a
using
declaration to tell the compiler that whenever you refer toset
, you meanstd::set
:(It's also possible to write a catch-all
using namespace std;
declaration that says that you always want to use everything from thestd
namespace, but that's normally considered bad practice. I mention it only because, despite being bad practice, it's fairly common, so you may well come across code that does it.)