注册 登录
编程论坛 C++教室

vc6.0不知道怎么iostream.h与string形式无法使用,用iostream却可以

w947367893 发布于 2017-10-31 20:43, 2018 次点击
比如
#include<iostream>
#include<string>
using namespace std;
class A
{private:string r;
public:A(string a)
       {r=a;}
       void print()
       {cout<<r<<endl;}
};
int main(){
A ob("1");
ob.print();
return 0;}可以
但是改头文件
#include<iostream.h>
#include<string>
class A
{private:string r;
public:A(string a)
       {r=a;}
       void print()
       {cout<<r<<endl;}
};
int main(){
A ob("1");
ob.print();
return 0;}
发生错误d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(4) : error C2146: syntax error : missing ';' before identifier 'r'
d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(4) : error C2501: 'string' : missing storage-class or type specifiers
d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(4) : error C2501: 'r' : missing storage-class or type specifiers
d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(5) : error C2629: unexpected 'class A ('
d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(5) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\program files (x86)\microsoft visual studio\myprojects\wqd\wq.cpp(11) : error C2440: 'initializing' : cannot convert from 'char [2]' to 'class A'
        No constructor could take the source type, or constructor overload resolution was ambiguous
3 回复
#2
rjsp2017-11-01 08:19
你为什么要 iostream.h 与 string 同时使用呢?

有句话叫“牛头不对马嘴”,<iostream.h>被C++废弃的时候<string>还不存在,<string>诞生的时候<iostream.h>已经被废弃。你怎么能认为它们会互相配合,它们需要互相配合的意义何在?

另外,不要再用VC6.0了,VC6.0开发于C++98之前,虽说后来又陆陆续续的发布了6个补丁,但对C++98的支持还是一团糟。何况其后C++又发布了 C++03、C++11、C++14、C++17,以及正在制定的C++20标准。你为什么要缠着一个过时的编译器不放?
#3
十三陵2017-11-02 21:56
vc++很古老了,iostream是c++库,统一不在使用.h格式,而c++98的c的库由*.h变成c*了..stdio.h写成cstdio
#4
zbzxpg2017-11-03 00:01
一楼的,我在VC6.0里测试下如:
#include<iostream>
#include<string>
using namespace std;

void main()
{
   string s;

}
编译没错误,你在<string>上点击右键,在弹出的菜单项中,选择 open Document <string>,看能否打开string.h头文件,如果看不到文件内容,说明你的IDE环境目录下没有string.h头文件,如果可以打开,可能就是其他问题了,我的QQ:358279267,联系我,可以帮你分析一下!
1