注册 登录
编程论坛 C++教室

关于文件输入输出的问题,求助!!

c453413516 发布于 2011-06-04 20:15, 497 次点击
以下是出错的源代码:
#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.

请教各位告诉,这是为什么?
3 回复
#2
ToBeStronger2011-06-04 20:30
楼主试试把那一行的automoblie改成*automoblie然后看看行不行
#3
specilize2011-06-05 17:49
楼主你好,我把你的代码拷贝到dev-C++,提示的错误和你的不同,为
 C:\Documents and Settings\Administrator\桌面\未命名1.cpp stray '\161' in program
我上网查了下,说这种错误是程序中带有全角符号,所以把
outFile << "make and mobel: " << automoblie << endl 这一句的<< automoblie 前面的空格删掉在写就可以了,运行正常
#4
ishagua2011-06-05 21:03
回复 3楼 specilize
和我想的一样
1