| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 809 人关注过本帖
标题:[求助]Accelerated c++ 里的一个例子,在vc++ 6.0下编译报错
只看楼主 加入收藏
jxlcs
Rank: 1
等 级:新手上路
帖 子:30
专家分:1
注 册:2008-7-27
结帖率:66.67%
收藏
 问题点数:0 回复次数:2 
[求助]Accelerated c++ 里的一个例子,在vc++ 6.0下编译报错
如题 , 不知道为啥这个书上的例子在vc++ 6.0下编译会提示错误

错误如下:
--------------------Configuration: 例子3-1加强版 - Win32 Debug--------------------
Compiling...
例子3-1加强版.cpp
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(16) : error C2039: 'precision' : is not a member of 'std'
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(16) : error C2873: 'precision' : symbol cannot be used in a using-declaration
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(43) : error C2653: 'vector<double,class std::allocator<double> >' : is not a class or namespace name
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(43) : error C2146: syntax error : missing ';' before identifier 'vec_sz'
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(43) : error C2065: 'vec_sz' : undeclared identifier
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(44) : error C2146: syntax error : missing ';' before identifier 'size'
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(44) : error C2065: 'size' : undeclared identifier
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(55) : error C2146: syntax error : missing ';' before identifier 'mid'
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(55) : error C2065: 'mid' : undeclared identifier
d:\users\sakuralove\documents\my program\c++\accelerated.c++\例子3-1加强版.cpp(63) : error C2065: 'midian' : undeclared identifier
执行 cl.exe 时出错.

例子3-1加强版.obj - 1 error(s), 0 warning(s)

完整程序:
/*
**accelerated c++ 例子3.1加强版
**计算学生成绩,家庭成绩以中值表示
*/

#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

using std::cin;            using std::sort;
using std::cout;        using std::streamsize;
using std::endl;        using std::string;
using std::precision;    using std::vector;
using std::setprecision;

int main()
{
    //请求输入并读入学生的姓名
    cout << "Please enter your first name: ";
    string name;
    cin >> name;

    //请求输入并读入学生的其中和期末成绩
    cout << "Please enter your midterm and final exam grades: ";
    double midterm, final;
    cin >> midterm >> final;

    //请求输入家庭作业成绩
    cout << "Enter all your homework grades, "
            "followed by end-of-file: ";
    vector<double> homework;
    double x;

    //不变式:homework 包含了所以的家庭作业成绩
    while (cin >> x) {
        homework.push_back(x);
    }

    //检查homework是否为空
    typedef vector<double>::size_type vec_sz;
    vec_sz size = homework.size();
    if (size == 0){
        cout << endl << "You must enter your grades. "
                     << "Please try again." <<endl;
        return 1;
    }

    //对程序排序
    sort(homework.begin(), homework.end());

    //计算家庭作业成绩的中值
    vec_sz mid = size/2;
    double median;
    median = (size % 2 == 0) ? (homework[mid] + homework[mid-1])/2 : homework[mid];

    //计算并输出总成绩
    streamsize prec = cout.precision();
    cout << "Your final grade is " << setprecision(3)
         << 0.2*midterm + 0.4*final + 0.4*midian
         << setprecision(prec) << endl;

    return 0;
}
搜索更多相关主题的帖子: documents cannot 
2012-11-26 21:19
mmmmmmmmmmmm
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:8
帖 子:388
专家分:1809
注 册:2012-11-2
收藏
得分:0 
用这个using namespace std;
程序代码:
/*
**accelerated c++ 例子3.1加强版
**计算学生成绩,家庭成绩以中值表示
*/

#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    //请求输入并读入学生的姓名
    cout << "Please enter your first name: ";
    string name;
    cin >> name;

    //请求输入并读入学生的其中和期末成绩
    cout << "Please enter your midterm and final exam grades: ";
    double midterm, final;
    cin >> midterm >> final;

    //请求输入家庭作业成绩
    cout << "Enter all your homework grades, "
            "followed by end-of-file: ";
    vector<double> homework;
    double x;

    //不变式:homework 包含了所以的家庭作业成绩
    while (cin >> x) {
        homework.push_back(x);
    }

    //检查homework是否为空
    typedef vector<double>::size_type vec_sz;
    vec_sz size = homework.size();
    if (size == 0){
        cout << endl << "You must enter your grades. "
                     << "Please try again." <<endl;
        return 1;
    }

    //对程序排序
    sort(homework.begin(), homework.end());

    //计算家庭作业成绩的中值
    vec_sz mid = size/2;
    double median;
    median = (size % 2 == 0) ? (homework[mid] + homework[mid-1])/2 : homework[mid];

    //计算并输出总成绩
    streamsize prec = cout.precision();
    cout << "Your final grade is " << setprecision(3)
         << 0.2*median + 0.4*final + 0.4*median    //这里midterm拼错了
         << setprecision(prec) << endl;

    return 0;
}

我们的目标只有一个:消灭0回复!
while(1)
++money;
2012-11-26 22:15
jxlcs
Rank: 1
等 级:新手上路
帖 子:30
专家分:1
注 册:2008-7-27
收藏
得分:0 
解决了 谢谢

 看来这本书比较老了啊~~~~
2012-11-27 14:49
快速回复:[求助]Accelerated c++ 里的一个例子,在vc++ 6.0下编译报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021927 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved