c++问题~
来源:百度知道 编辑:UC知道 时间:2024/08/31 11:03:58
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
void instructions();
void q(ifstream& in,ofstream& out);
void header(ofstream& out);
void footer(ofstream& out);
char myfile(15),yourfile(15);
ifstream in;
ofstream out;
void main(){
instructions();
header(out);
q(in,out);
footer(out);
}
void instructions(){
cout<<"请创建好你的文件,并在下一步输入你的文件名"<<endl;
}
void q(ifstream& in,ofstream& out){
cout<<"请输入你要读取的文件名"<<endl;
cin>>myfile;
in.open(myfile);
if(in.fail()){
cout<<"读取文件失败"<<endl;
exit(1);
}
cout<<"请输入你要读入的文件名"<<endl;
cin>>yourfile;
out.open(yourfile);
if(out.fail()){
cout<<"写入失败"<<endl;
exit(1);
}
char x;
#include<fstream>
#include<cstdlib>
using namespace std;
void instructions();
void q(ifstream& in,ofstream& out);
void header(ofstream& out);
void footer(ofstream& out);
char myfile(15),yourfile(15);
ifstream in;
ofstream out;
void main(){
instructions();
header(out);
q(in,out);
footer(out);
}
void instructions(){
cout<<"请创建好你的文件,并在下一步输入你的文件名"<<endl;
}
void q(ifstream& in,ofstream& out){
cout<<"请输入你要读取的文件名"<<endl;
cin>>myfile;
in.open(myfile);
if(in.fail()){
cout<<"读取文件失败"<<endl;
exit(1);
}
cout<<"请输入你要读入的文件名"<<endl;
cin>>yourfile;
out.open(yourfile);
if(out.fail()){
cout<<"写入失败"<<endl;
exit(1);
}
char x;
变量定义错了:
char myfile(15),yourfile(15);
改成
char myfile[15],yourfile[15];
就OK了
#include <stdio.h>
/*交换两个数*/
void Swap(int &a, int &b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
}
/*输出一行十个数字*/
void Write(int array[], int begin, int end)
{
for(int i = begin; i <= end; i ++)
// cout <<array[i] << " ";
printf("%d ",array[i]);
printf("\n");
// cout << endl;
}
/*插入排序*/
void InsertionSort(int array[], int begin, int end)
{
int i, j;
int tmp;
for(i = begin+1; i <= end; i ++) /*循环几次就输出几行*/
{
tmp = array[i];
for(j = i-1; j >= begin; j --)
{
if(tmp > array[j]) /*如果要从小到大排序,则改将'>'改为'<'*/
array[j + 1] = array[j];
else
break;
}
array[j+1] = tmp;
Wri