Просмотр полной версии : Помогите (C++)
Создать программу, обеспечивающую ввод пользователем 10 строк с клавиатуры, запись этих строк в файл и последующее чтение из файла.
З.Ы. Борланд С++, консоль
herfleisch
20.01.2009, 21:10
Пиши мне в асю. Приеду домой - помогу.
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
ofstream ufile;
string uinput;
cout<<"Введите 10 строк: "<<endl;
ufile.open("file.txt", ios::app);
if(ufile.is_open())
{
for(int i = 0; i < 10; i++)
{
cin>>uinput;
ufile<<uinput<<"\n";
}
ufile.close();
}
else
{
cout<<"Ошибка открытия файла!";
}
system("cls");
cout<<"Содержимое: "<<endl<<endl;
ifstream ufiler;
ufiler.open("file.txt");
if(ufiler.is_open())
{
while(!ufiler.eof())
{
ufiler>>uinput;
cout<<uinput<<endl;
}
ufiler.close();
}
else
{
cout<<"Ошибка открытия файла!";
}
_getch();
return 0;
}
vBulletin® v3.8.14, Copyright ©2000-2026, vBulletin Solutions, Inc. Перевод: zCarot