C++问题,改代码

来源:百度知道 编辑:UC知道 时间:2024/05/23 15:09:22
// test2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "iostream"

public class Blankbook
{
private:
char name[10];
char account[5];
double saving;
public:
Blankbook(char *xname,char *xaccount,double xsaving);
Blankbook operator+(double i);
Blankbook operator-(double i);
friend ostream &operator<<(ostream &os,const Blankbook &b);
};

Blankbook::Blankbook(char *xname,char *xaccount,double xsaving)
{ strcpy(name,xname);
strcpy(account,xaccount);
saving=xsaving;
}
Blankbook Blankbook::operator +(double i)
{
Blankbook c;
c.saving=saving+i;
strcpy(c.name,name);
strcpy(c.account,account);
return c;
}

Blankbook Blankbook::operator -(double i)
{
Blankbook c;
c.saving=saving-i;

1.public class Blankbook <----- 错误,去掉public
2.Blankbook c; <----- 错误, Blankbook 类没有默认的构造可用,在
class Blankbook 中添加 Blankbook();或者
带参数声明, 即 Blankbook c (xname, xaccount, xsaving);
3. 在#include "iostream" 后面添加一行 using namespace std;

fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
是不是原来编了一个文件的哟!!