C
cplusplusquestion
In following code, the statement:
fd1 << "this is test";
can't write into a file. I don't know why.
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
void read(istream& fd){
string buffer;
getline(fd,buffer);
while(!fd.eof()) {
getline(fd, buffer);
}
}
int main(int argc, char **argv) {
if (argc < 2){
cout << "arg less than 2\n";
exit(1);
}
ifstream fd(argv[1], ios::in | ios:ut);
if (!fd){
cerr << "cannot open first file" << argv[1] << endl;
exit(1);
}
while (!fd.eof()){
read(fd);
fstream fd1(argv[2], ios::in | ios:ut);
if (!fd1){
cerr << "cannot open second" << argv[2] << endl;
exit(1);
}
while (!fd1.eof()){
read(fd1);
fd1 << "this is test";
}
fd1.close();
}
fd.close();
return 0;
}
fd1 << "this is test";
can't write into a file. I don't know why.
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
void read(istream& fd){
string buffer;
getline(fd,buffer);
while(!fd.eof()) {
getline(fd, buffer);
}
}
int main(int argc, char **argv) {
if (argc < 2){
cout << "arg less than 2\n";
exit(1);
}
ifstream fd(argv[1], ios::in | ios:ut);
if (!fd){
cerr << "cannot open first file" << argv[1] << endl;
exit(1);
}
while (!fd.eof()){
read(fd);
fstream fd1(argv[2], ios::in | ios:ut);
if (!fd1){
cerr << "cannot open second" << argv[2] << endl;
exit(1);
}
while (!fd1.eof()){
read(fd1);
fd1 << "this is test";
}
fd1.close();
}
fd.close();
return 0;
}