SP_*_*SP_ 1 c++ string header visual-studio-2008
我正在学习Visual C++ 2008中的C++编程,快速版.我的程序没有识别std::string数据类型.我已经包括了<string>图书馆.
#include "stdafx.h"
#include <iostream>
#include "TestClass.h"
#include <string>
using namespace std;
class Rectangle {
private:
int width;
int height;
double area;
string name;
public:
Rectangle()
{
width = 0;
height = 0;
}
int getWidth()
{
return width;
}
int getHeight()
{
return height;
}
void setWidth(int width)
{
this->width = width;
}
void setHeight(int height)
{
this->height= height;
}
void setArea( )
{
area = width * height;
}
double getArea( )
{
return area;
}
Rectangle (const Rectangle & x)
{
this->area = x.area;
}
void friendtestfunction(Rectangle2 s)
{
cout << "" << s.name;
}
};
int Rectangle2::stat_var = 5;
int _tmain(int argc, _TCHAR* argv[])
{
Rectangle rect;
rect.setWidth(10);
rect.setHeight(20);
rect.setArea( );
cout<< "height is equal to :" << rect.getHeight() << endl;
cout<< "width is equal to :" << rect.getWidth() << endl;
cout << "area is equal to :" << rect.getArea() << endl;
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我在类Rectangle中声明类型为string的私有变量时,它显示以下错误:
1>c:\users\subith.p\documents\visual studio 2008\projects\test\test\testclass.h(10) : error C2146: syntax error : missing ';' before identifier 'name'
1>c:\users\subith.p\documents\visual studio 2008\projects\test\test\testclass.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |