错误1:头文件名称错误,应该为#include
错误2:使用cout函数没有定义命名空间,应该加上using namespace std,或者使用std::cout的形式
错误3:setFeet、setInches两个函数返回值为void(即不返回),同时他们俩都要有相应的参数,在cout< 修改后的代码:#include
using namespace std;
struct Distance
{
int iFeet;
float fInches;
void setFeet(int x)
{
iFeet = x;
}
int getFeet()
{
return iFeet;
}
void setInches(float y)
{
fInches = y;
}
float getInches()
{
return fInches;
}
};
void main()
{
Distance d1, d2;
d1.setFeet(2);
d1.setInches(2.2);
d2.setFeet(3);
d2.setInches(3.3);
cout << d1.iFeet << " " << d1.fInches << endl;
cout << d2.iFeet << " " << d2.fInches << endl;
}
strncpy是不安全,它不检查边界,所以建议在vs中就用CString。如果只是练手,可以自己写个strncpyX函数来替代原来的