以下程序,用了using namespace std;这条语句,没有问题。但如果不用using namespace std;这条语句,而是采用std:string word;这种形式,如果修改才能通过编译呢?望各位高人指教,谢谢!#include <iostream>
#include <fstream>
#include <string>
using namespace std;int main()
{
ofstream outfile("out_file");
ifstream infile("in_file");if(!infile){
cerr<<"error:unable to open input file!"<<endl;
return -1;
}
if(!outfile){
cerr<<"error:unable to open output file!"<<endl;
return -2;
}string word;
while(infile>>word)
outfile<<word<<' ';return 0;
}
#include <fstream>
#include <string>
using namespace std;int main()
{
ofstream outfile("out_file");
ifstream infile("in_file");if(!infile){
cerr<<"error:unable to open input file!"<<endl;
return -1;
}
if(!outfile){
cerr<<"error:unable to open output file!"<<endl;
return -2;
}string word;
while(infile>>word)
outfile<<word<<' ';return 0;
}
void main(){ std::cout<<"fanqing";
}
#include <fstream>
#include <string>int main()
{
std::ofstream outfile("out_file");
std::ifstream infile("in_file");if(!infile){
std::cerr<<"error:unable to open input file!"<<std::endl;
return -1;
}
if(!outfile){
std::cerr<<"error:unable to open output file!"<<std::endl;
return -2;
}std::string word;
while(infile>>word)
outfile<<word<<' ';return 0;
}
我举了个最简单的例子(只是提供思路,接下来你照样话葫芦不就可以了)
就要在他们前面都加上std:: 建议看看c++的书。