C++怎样定义string类型变量,为什么总报错 5
#include<iostream.h>#include<string>usingnamespacestd;intmain(){stringc="hijklmn";cou...
#include<iostream.h>
#include<string>
using namespace std;
int main()
{
string c="hijklmn";
cout<<c;
return 1;
}
ompiling...
1.cpp
d:\vc6++ (g)\vc98\include\ios(16) : error C2143: syntax error : missing ';' before ''template<''
d:\vc6++ (g)\vc98\include\ios(16) : error C2501: '_STD_BEGIN' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(17) : error C2504: 'ios_base' : base class undefined
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(20) : error C2143: syntax error : missing ';' before '<'
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(20) : error C2059: syntax error : '<'
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(118) : error C2228: left of '.setf' must have class/struct/union type
d:\vc6++ (g)\vc98\include\ios(118) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(118) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(118) : error C2065: 'adjustfield' : undeclared identifier
d:\vc6++ (g)\vc98\include\ios(120) : error C2143: syntax error : missing ';' before '&'
d:\vc6++ (g)\vc98\include\ios(120) : error C2433: 'ios_base' : 'inline' not permitted on data declarations
d:\vc6++ (g)\vc98\include\ios(120) : error C2501: 'ios_base' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(120) : error C2086: 'ios_base' : redefinition
d:\vc6++ (g)\vc98\include\ios(120) : error C2061: syntax error : identifier 'ios_base'
d:\vc6++ (g)\vc98\include\ios(121) : error C2501: 'left' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(121) : error C2228: left of '.setf' must have class/struct/union type
d:\vc6++ (g)\vc98\include\ios(121) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(121) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(121) : fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
1.obj - 102 error(s), 5 warning(s)
写程序时只要不用string类型变量都可以解决,但是一定义string类型变量都出现以上错误。这与创建工程有关吗? 展开
#include<string>
using namespace std;
int main()
{
string c="hijklmn";
cout<<c;
return 1;
}
ompiling...
1.cpp
d:\vc6++ (g)\vc98\include\ios(16) : error C2143: syntax error : missing ';' before ''template<''
d:\vc6++ (g)\vc98\include\ios(16) : error C2501: '_STD_BEGIN' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(17) : error C2504: 'ios_base' : base class undefined
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(20) : error C2143: syntax error : missing ';' before '<'
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(20) : error C2059: syntax error : '<'
d:\vc6++ (g)\vc98\include\ios(95) : see reference to class template instantiation 'basic_ios<_E,_Tr>' being compiled
d:\vc6++ (g)\vc98\include\ios(118) : error C2228: left of '.setf' must have class/struct/union type
d:\vc6++ (g)\vc98\include\ios(118) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(118) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(118) : error C2065: 'adjustfield' : undeclared identifier
d:\vc6++ (g)\vc98\include\ios(120) : error C2143: syntax error : missing ';' before '&'
d:\vc6++ (g)\vc98\include\ios(120) : error C2433: 'ios_base' : 'inline' not permitted on data declarations
d:\vc6++ (g)\vc98\include\ios(120) : error C2501: 'ios_base' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(120) : error C2086: 'ios_base' : redefinition
d:\vc6++ (g)\vc98\include\ios(120) : error C2061: syntax error : identifier 'ios_base'
d:\vc6++ (g)\vc98\include\ios(121) : error C2501: 'left' : missing storage-class or type specifiers
d:\vc6++ (g)\vc98\include\ios(121) : error C2228: left of '.setf' must have class/struct/union type
d:\vc6++ (g)\vc98\include\ios(121) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(121) : error C2653: 'ios_base' : is not a class or namespace name
d:\vc6++ (g)\vc98\include\ios(121) : fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
1.obj - 102 error(s), 5 warning(s)
写程序时只要不用string类型变量都可以解决,但是一定义string类型变量都出现以上错误。这与创建工程有关吗? 展开
4个回答
展开全部
#include<iostream.h>
改为
#include<iostream>
改为
#include<iostream>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有#include完全相关的头文件,到网上查查,string的需要什么头文件,string一般定义在MFC中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建立一个空项目
添加C++文件
把代码复制过去
你用的是什么编译器?
添加C++文件
把代码复制过去
你用的是什么编译器?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询