| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 497 人关注过本帖
标题:关于文件输入输出的问题,求助!!
只看楼主 加入收藏
c453413516
Rank: 1
等 级:新手上路
帖 子:16
专家分:4
注 册:2010-12-5
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:3 
关于文件输入输出的问题,求助!!
以下是出错的源代码:
#include <iostream>
#include <fstream>

int main()
{
    using namespace std;

    char automoblie[50];
    int year;
    double a_price;
    double d_price;

    ofstream outFile;
    outFile.open("carinfo.txt");

    cout << "Enter the make and model of automobile: ";
    cin.getline(automoblie, 50);
    cout << "Enter the model year: ";
    cin >> year;
    cout << "Enter the origianl asking price: ";
    cin >> a_price;
    d_price = 0.913 * a_price;

    cout << fixed;
    cout.precision(2);
    cout.setf(ios_base::showpoint);
    cout << "make and model: " << automoblie << endl;
    cout << "year: " << year <<endl;
    cout << "was asking $" << a_price << endl;
    cout << "now asking $" << d_price << endl;

    outFile << fixed;
    outFile.precision(2);
    outFile.setf(ios_base::showpoint);
    outFile << "make and mobel: " << automoblie << endl;//如果把这行除去,那么程序将成功执行,但是如果有这一行,将会提示出错,出错提示如下
    outFile << "year: " << year << endl;
    outFile << "was asding $" << a_price << endl;
    outFile << "now asking $" << d_price << endl;

    outFile.close();
    return 0;
}


错误提示::E:\MY PROJECT\test009\test009.cpp(35) : error C2018: unknown character '0xa1'
E:\MY PROJECT\test009\test009.cpp(35) : error C2018: unknown character '0xa1'
Error executing cl.exe.

请教各位告诉,这是为什么?
搜索更多相关主题的帖子: 源代码 
2011-06-04 20:15
ToBeStronger
Rank: 4
等 级:业余侠客
帖 子:61
专家分:239
注 册:2011-4-8
收藏
得分:7 
楼主试试把那一行的automoblie改成*automoblie然后看看行不行
2011-06-04 20:30
specilize
Rank: 4
等 级:业余侠客
帖 子:126
专家分:247
注 册:2011-2-20
收藏
得分:7 
楼主你好,我把你的代码拷贝到dev-C++,提示的错误和你的不同,为
 C:\Documents and Settings\Administrator\桌面\未命名1.cpp stray '\161' in program
我上网查了下,说这种错误是程序中带有全角符号,所以把
outFile << "make and mobel: " << automoblie << endl 这一句的<< automoblie 前面的空格删掉在写就可以了,运行正常
2011-06-05 17:49
ishagua
Rank: 2
等 级:论坛游民
帖 子:30
专家分:54
注 册:2011-5-10
收藏
得分:7 
回复 3楼 specilize
和我想的一样
2011-06-05 21:03
快速回复:关于文件输入输出的问题,求助!!
数据加载中...
 
   



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

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