I can do this or not ??

Hello everyone

I need help please

I have this first file " .txt " by name " name of emoji " :

https://i.postimg.cc/hGNN31mt/1-1.png

and I have this second file " .txt " by name " java code " :

https://i.postimg.cc/657nBV4X/1-2.png

Now I want create file ".txt" number three from ( first + second ) like this :

https://i.postimg.cc/jjNQhH4T/1-3.png by name " grinning "

and number four like this :

https://i.postimg.cc/F15h0QrN/1-3.png by name " smiley "

and do this for all lines the file ( 1 and 2 ) I means do this 1805 times by for loop ... can anyone help me please ❤️ ❤️ ❤️
Last edited on
Post a sample of the 2 files (first, second).

@seeplus

this is the first :

https://www.cjoint.com/doc/20_11/JKinc2An5rC_name-of-emoji.txt


and this is the second :

https://www.cjoint.com/doc/20_11/JKingrqdO5C_java-code.txt


and Thinks bro in advanced ❤️ ❤️ ❤️
Is this what you want:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>
#include <iostream>
#include <string>

int main()
{
	std::ifstream if1("emoji.txt");
	std::ifstream if2("code.txt");

	if (!if1.is_open() || !if2.is_open())
		return (std::cout << "Cannot open files\n"), 1;

	for (std::string f1, f2; std::getline(if1, f1) && std::getline(if2, f2); ) {
		std::ofstream of(f1);
		of << f1 << '\n' << f2 << '\n';
	}
}

Yes, it can be done. Open each file for reading and if they both opened successfully you:

Read the contents of each file into two strings (std::string really recommended), one string for each file, one line at a time, reading the files as the condition statement for a while loop makes it easy to stop the loop when the end of either file is read.

Within the while loop block:

1. For the output file name you create a string with the read emoji name and concatenate it with ".txt"

2. Open for writing a file using the created file name.

3. Write the read code string to the file.

4. Close the file.

5. The loop repeats until either file has been read to EOF.

@seeplus

there is an error bro I'm sorry:

https://i.postimg.cc/sgH0dtyS/Untitled.png
Does your compiler support C++11?

Please don't provide an image. It's unreadable. Post the actual error message.
Last edited on
Does this compile? If it does, your compiler doesn't support C++11. The above code compiles OK with VS2019 - which is the only compiler I use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>
#include <iostream>
#include <string>

int main()
{
	std::ifstream if1("emoji.txt");
	std::ifstream if2("code.txt");

	if (!if1.is_open() || !if2.is_open())
		return (std::cout << "Cannot open files\n"), 1;

	for (std::string f1, f2; std::getline(if1, f1) && std::getline(if2, f2); ) {
		std::ofstream of(f1.c_str());
		of << f1 << '\n' << f2 << '\n';
	}
}

Last edited on
@seeplus

Yes Yes This is exactly what I want Thank you so much bro ❤️ ❤️ ❤️

last question please the file was created is not " .txt " how I can do it ??

https://i.postimg.cc/dt5K3NwQ/Untitled.png
Last edited on
If the last code compiles OK, then you're using a C++98 compiler - which is vastly out of date. I'd really suggest updating to a current C++ compiler (C++17/20).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>
#include <iostream>
#include <string>

int main()
{
	std::ifstream if1("emoji.txt");
	std::ifstream if2("code.txt");

	if (!if1.is_open() || !if2.is_open())
		return (std::cout << "Cannot open files\n"), 1;

	for (std::string f1, f2; std::getline(if1, f1) && std::getline(if2, f2); ) {
		std::ofstream of((f1 + ".txt").c_str());
		of << f1 << '\n' << f2 << '\n';
	}
}

@seeplus

Yes Now it's very coooooooooooooooooooooooooooooool brother lot of thanks ❤️ ❤️ ❤️
Topic archived. No new replies allowed.