help

I read two txt files in response argv and put it in outstream
and in output txt is nothing
help
and must be in order
ex
lini1
line2
line3
etc

not this in with duble only


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include <fstream>    
#include <iostream>
#include <string>
using namespace std;


int main(int argc, char* argv[])
{
	ifstream input;
	ifstream compare;
	ofstream output;
	string line_input, line_compare;

	input.open(argv[1]);
	output.open(argv[2]);

	while (!input.eof())
	{
		getline(input, line_input);

		compare.open(argv[3]);
		while (!compare.eof())
		{
			getline(compare, line_compare);


			if (line_input == line_compare)
			{
				output << line_input << endl;
			}
		}
		compare.close();

	}

	cout << endl;
	input.close();
	output.close();

	system("pause");
	return 0;
}
Last edited on
It works, maybe it couldn't find the file and you have no warning msg if it cant.
I want to display both text messages

in output txt

if (line_input == line_compare)
{
output << line_input << endl;
}
now show only equality words in output
Last edited on
?
Did files opened succesfully?
Check for this.
yes
but I need
ex
now the program
file1.txt
A
B
C
file2.txt
A
D
E
output.txt
A

I want to
file1.txt
A
B
C
file2.txt
A
D
E
output.txt
A
B
C
A
D
E



If you want to display both files, then display both files. Get rid of the comparison junk and just output files sequentially.

1
2
3
4
5
6
7
8
#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
    std::ifstream i1(argv[1]), i2(argv[3]);
    std::ofstream(argv[2]) << i1.rdbuf() << i2.rdbuf();
}
Last edited on
I need this code
Last edited on
I believe I just posted code to do that.
Topic archived. No new replies allowed.