用vc写STL程序需要VC的什么特别的设置吗?

dragonfly 2001-02-11 01:41:00
小弟初学,还请各位大虾指导:
以下这段代码时教科书上的,可是在我的vc里面就是编译不了,各位大虾,究竟是真么回事啊?需要vc的环境进行什么设置吗?
谢谢!

#include <list>
#include <string>
#include <iostream>

using namespace std ;

typedef list<string> LISTSTR;

void main()
{
LISTSTR test;

test.push_back("back");
test.push_front("middle");
test.push_front("front");

// front
cout << test.front() << endl;

// back
cout << test.back() << endl;

test.pop_front();
test.pop_back();

// middle
cout << test.front() << endl;
}
...全文
328 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
duke_software 2001-02-16
  • 打赏
  • 举报
回复
Haven't got answer? See the questions and bugs from MSDN. Do not know how? ....
bugn 2001-02-15
  • 打赏
  • 举报
回复
to dragonfly:

请详细描述出错的原文,我不信这里这么多人还有解决不了的问题.
vcmfc 2001-02-15
  • 打赏
  • 举报
回复
继续接收新经验....,hehe......
vcmfc 2001-02-15
  • 打赏
  • 举报
回复
结贴!
dragonfly 2001-02-14
  • 打赏
  • 举报
回复
谢谢,各位了虽然没有解决问题
但至少得到了大家的热心帮助谢谢~!
问题本身没有解决
但我想了一个办法绕过了这个问题
等忙过这缎时间,再回来和大家一起探讨C++的问题
duke_software 2001-02-14
  • 打赏
  • 举报
回复
I think most guys here don't know much of STL, including (超级菜鸟). You must know what STL is and what Win32 console is.

The code above is a standard ANSI C++ program. Try it in UNIX using g++ to compile, I bet it can go through and work well. If you want to use VC, just put "typedef list<string> LISTSTR;" into the main() function. This time it can work, but it will have some warnings. The "typedef" in VC can't be put outside a function(main()), why? Think about it, you'll find the answer.

zzbsw 2001-02-13
  • 打赏
  • 举报
回复
Open VC,
1.File->new->C++ source file;
2.Copy the source code to the file which you have created.
3.F7.
4.(My computer)0 error,4 warnings.
5.Ctr+F5
6.Pop up the Dos dialog and display the result.
7.Press any key and return.
jjww 2001-02-12
  • 打赏
  • 举报
回复
你这种报错我也碰到过,我那次情况是这样的。
我也是在我的MDI里自己写了个链表类,把类的头文件包含进stdafx.h后,这时如果类的实现文件包含该类的头文件的话,就报这个错,如果把包含的头文件改成stdafx.h,就好了。
希望对你有用。
bugn 2001-02-12
  • 打赏
  • 举报
回复
是问题总是有原因的,大家要学会分析问题的能力,一般情况下最好不要回避它:

> 不是啦,我现在的问题是,一编译就说在与编译扫描的时候不希望的文件结尾,
看这句话,最好把原来的英文打出来,你翻译的是否有问题呢,或者没有说全?

我估计是c1010错误,去MSDN里查C1010,你就会看到问题的解释,以及问题的解决方法了。
如果是的话,就按vcmfc的办法就差不多了。要不然就这样:在workspace->fileview-><yourfile>->right mouse click->settings->c/c++ ->precompiles headers->select [not using ...] or [automatic ...]
至于什么是precompiled headers,去仔细看看文档。





dragonfly 2001-02-11
  • 打赏
  • 举报
回复
不是啦,我现在的问题是,一编译就说在与编译扫描的时候不希望的文件结尾,
肯定时库里面的预编译指令的问题?可是究竟是怎么回事呢,我现在想在我的项目里面用一个链表[不利用MFC类],所以希望在里面使用<list>,可惜不知道时怎么回事,那位大虾指点指点如何?
vcmfc 2001-02-11
  • 打赏
  • 举报
回复
少了这一行:#include "stdafx.h"
vcmfc 2001-02-11
  • 打赏
  • 举报
回复
是Main的问题!,建议用VC的Win32 comsole application 向导生成一个应用程序,再把上述代码加入!
hyqryq 2001-02-11
  • 打赏
  • 举报
回复
tc不支持STL.

用Win32 comsole application
chikic 2001-02-11
  • 打赏
  • 举报
回复
你用的是vc++6.0吧!用tc试试!
vcmfc 2001-02-11
  • 打赏
  • 举报
回复
没招了,只能用VC的Win32 comsole application 向导生成一个应用程序,再把上述代码加入!
dragonfly 2001-02-11
  • 打赏
  • 举报
回复
可是我这里怎么就时不行啊!7456
不过还是谢谢
hyqryq 2001-02-11
  • 打赏
  • 举报
回复
我试过了,可以呀!
Fenian 2001-02-11
  • 打赏
  • 举报
回复
在头文件后加:
using namespace std;

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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