请问想在mfc中用vector,set类的容器,怎么用?

ChenLau 2004-03-17 04:36:56
我试过了#include<vector>,#include<set>不行,用std::前缀也不好使。
我想问问怎样才能在mfc中用vector呢?

我是想把原来的c++程序(全部都是类实现的,也就是上几篇帖子提问的那个读文件的程序),改成基于窗体的mfc exe。

我是不是在mfc中insert class 然后添加generic class,把我自己原先基于标准库的类实现放进去就行啊!
当然原来用的标准库都要改!

请告诉我mfc中怎么用vector!!谢谢!


...全文
183 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChenLau 2004-03-17
  • 打赏
  • 举报
回复
对不起,您误解我的意思了,我不是编写控制台的程序

我编写的是MFC AppWizard(exe)程序,然后里面想用vector,set和string这些标准库中的东西

可是用#include<vector> #include<set> #include<string>都加了。using namespace std也用了,可是却报错。

错误在上面的回帖中有详细记录。

请问该怎么解决?
Darkay_Lee 2004-03-17
  • 打赏
  • 举报
回复
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> localVal;
return 0;
}

VC6.0中肯定可以,你检查一下Tools-->Options-->Directories,看里面的include路径设置有没有被改了啊
ChenLau 2004-03-17
  • 打赏
  • 举报
回复
我新建了一个基于对话框的mfc exe工程,名字为read,然后我单击insert菜单的new class子菜单,从弹出的对话框中的class type中选择generic class(普通类),然后在Name处输入classname,创建一个名为classname的普通类,然后我在classname类中加入两个私有成员:CString name;vector<CString> values;(本来我是想用string类的,可是发现mfc中string也没法用,出错)。
我在classname.cpp的顶部加了#include<vector>,也用了using namespace std;
但是还是有错
错误就出现在声明处
vector<CString> values;

错误如下:
c:\作业\c++\inherit\read\classname.h(22) : error C2143: syntax error : missing ';' before '<'
c:\作业\c++\inherit\read\classname.h(22) : error C2501: 'set' : missing storage-class or type specifiers
c:\作业\c++\inherit\read\classname.h(22) : error C2059: syntax error : '<'
c:\作业\c++\inherit\read\classname.h(22) : error C2238: unexpected token(s) preceding ';'

我用的是vc6.0,另外为什么我用#include<string>,std也用了,可是string也不能用,难道必须用CString么?

mfc中不能有标准库么?
cgsw12345 2004-03-17
  • 打赏
  • 举报
回复
上面说的一样,先include要包含的文件名,再打开命名空间就可以了!
Mephisto_76 2004-03-17
  • 打赏
  • 举报
回复
#include <vector>
using namespace std;
ChenLau 2004-03-17
  • 打赏
  • 举报
回复
??没人帮忙?

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧