ofil(ofstream)文件输出流
源码:#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
void swap(int val1,int val2){
ofil<<"swap("<<val1
<<","<<val2<<")\n";
int temp=val1;
val1=val2;
val2=temp;
ofil<<"after swap():val1"<<val1
<<"val2:"<<val2<<"\n";
}
void display(vector<int> vec){
for(int ix=0;ix<vec.size();++ix)
cout<<vec<<' ';
cout<<endl;
}
ofstream ofil("text_out1");
void bubble_sort(vector<int> vec){
for(int ix=0;ix<vec.size();++ix){
for(int jx=ix+1;jx<vec.size();++jx){
if(vec>vec){
//调试用的输出信息
ofil<<"about to call swap!"
<<"ix:"<<ix<<"jx:"<<jx<<'\t'
<<"swapping:"<<vec
<<"with"<<vec<<endl;
//ok:交换两个元素...
swap(vec,vec);
}
}
}
}
intmain(){
int ia={8,34,3,13,1,21,5,2};
vector<int> vec(ia,ia+8);
cout<<"vetor before sort:";
display(vec);
bubble_sort(vec);
cout<<"vector after sort: ";
display(vec);
return 0;
}
报错:
Error:'ofil' was notdeclared in this scope ofstream ofil("text_out1");
你只是说明了函数,却没有函数定义实体,所以报错。
页:
[1]