나는 자동차에 관한 데이터를 입력하라는 메시지를 표시합니다. Do ... while() 루프는 처음에는 잘 작동하지만 처음에는 제대로 작동하지 않습니다. 이 코드는 우울하고 Dev-C++을 사용하고 있습니다. 도와 주셔서 감사합니다. * ** * * 프로그램의 outpu* ** * ** * * Do ... While() 루프가 제대로 작동하지 않습니다.
for each car please enter :
The manufacturer: Toyota
The model: corolla
The year: 2005
The miles: 123,000
The cost of car $: 7,999
Do you want to continue?y
The manufacturer: The model: Honda
The year: Civic
The miles: 67,850
The cost of car $: 9,200
Do you want to continue?n
#include <iostream>
#include<conio.h>
#include<cstring>
#include<fstream>
#include <iomanip.h>
using namespace std;
int main()
{
char manufacturer[16], model[16], year[10], miles[10], car_cost[12];
char response;
ofstream OS ("usedcars.txt", ios::out);
cout<<"for each car please enter :"<<endl;
do
{
ofstream OS ("usedcars.txt", ios::app);
cout<<"The manufacturer: ";
cin.getline(manufacturer, 16);
cout<<"The model: ";
cin.getline(model, 16);
cout<<"The year: ";
cin.getline(year, 8);
cout<<"The miles: ";
cin.getline(miles, 8);
cout<<"The cost of car $: ";
cin.getline(car_cost, 10);
OS << manufacturer << setw(9) << model << setw(8) << year << setw(11)<< miles << setw(8) << car_cost << endl;
cout<<"Do you want to continue?";
cin>>response;
}
while (response!='n');
return 0;
}
**
** *usedcars.txt* ** * ** * ** * ** * *
Toyota corolla 2005 123,000 7,999
Honda Civic 67,850 9,200
*이 처음으로 정상적으로 작동하지 않으면 스트림을 닫아야합니다. * 정지합니다. 중단되며, 폭발합니다. 폭발합니다. 네가 구체적으로 말하지 않으면 어떻게 알 수 있니? –
아니오, "die in flames"라고 생각합니다 :) – sirgeorge
usedcars.txt 파일이 비어 있거나 오류 일 수 있습니다. – Ben