一到C++题目,高分等答案

来源:百度知道 编辑:UC知道 时间:2024/06/11 02:31:49
建立一个文本文件,从键盘中输入一篇短文存放在文件中.短文由若干行构成,每行不超过80个字符.
不行

#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ofstream outfile("data.txt");
char line[81];
// END终止输入,可改成其它字符串
char *end = "END";

if (!outfile)
{
cerr << "Can not open file." << endl;
exit(-1);
}

while (1)
{
cin.getline(line, 81);

if (!strcmp(line, end))
break;

outfile << line << endl;
}

outfile.close();
return 0;
}

mian()
{
char ans[1000][80];
char model[80];
int i=0;
while(cin>>model)
strcpy(ans[i++],model);
int j=0;
while(j<=i)
cout<<ans[j]<<endl;
}

#include "stdio.h"
#include "string.h"

#define MAX 80
void main()
{