LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1020|回复: 8

为什么不能定义string变量

[复制链接]
发表于 2003-7-24 12:43:26 | 显示全部楼层 |阅读模式
书上的例程:
#include<iostream.h>
#include<fstream.h>
#include<string.h>

int main()
{
        ofstream outfile("out_file");
        ifstream infile("in_file");

        if(! infile)
        {
                cerr<<"error:unable to open input file!\n";
                return -1;
        }

        if(!outfile)
        {
                cerr<<"error:unable to open output file!\n";
                return -2;
        }

        string word ;
        while (infile>>word)
        {
        outfile<<word<<' ';
        }
        return 0;
}

编译时报错:22:Undefined symbol 'string'
22:Statement missing;
23:Undefined symbol 'word'
如果将22行换成char word[];程序就没有问题。请大侠帮我看看究竟是什么问题。谢谢了。
发表于 2003-7-24 13:14:47 | 显示全部楼层
#include<string>
using namespace std;
 楼主| 发表于 2003-7-25 19:54:47 | 显示全部楼层
呵呵,加了using namespace std;以后这一句报语法错误。忘了说了。用的是TC++3.0+win2000pro
发表于 2003-7-25 21:48:39 | 显示全部楼层
TC不支持很多新的C++特性,你还是换一个编译器吧。
发表于 2003-7-26 11:51:27 | 显示全部楼层
STL只是19976以后才开始制定的(时间可能会记错)

TC则是早期的编译器 后面也没有人维护了

所以你还是换个编译器吧
如果想学习C++的话
发表于 2003-7-26 13:47:19 | 显示全部楼层
Borland C++行不行
发表于 2003-7-26 17:05:46 | 显示全部楼层
恐怕不行。建议你在windows下用dev-c++。
http://www.bloodshed.net/
 楼主| 发表于 2003-7-26 21:38:52 | 显示全部楼层
dev-c++很好么?可是那里才能买(下)得到呢?
 楼主| 发表于 2003-7-26 22:05:09 | 显示全部楼层
性子急,没有看到版主里面就有地址。先谢谢了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表