0
I need help with fstream 😁
I have 2 text documents witht the names : names.txt and website.txt, in the document names.txt is the content : Duck, Donald, 4.4.1990 Kong, King, 9.9.1999 And website.txt : <body> <h1>shortlist</h1> <p>%</p> My question how I create a new document, like web.txt and replace the % against the content in names.txt. My idea and code : 1) I read with ifstream my 2 documents files, like : ifstream file("names.txt"); ifstream file2("website.txt"); Now i want to create new file like web.txt and replace the % against my names in the file names.txt ofstream file3("web.txt"); file3 << file; --> copy doesnt work 😂 file3.close(); Can somebody help me and explain what I need to do :D?
1 Odpowiedź
+ 3
You could try to read in "names.txt" and store everything up to "%" to a string called firstPart.
Then read in the rest to a string called lastPart.
Then read in "website.txt" to a string called middlePart.
Now write to a new file ,"web.txt", starting with firstPart, then middlePart, then lastPart.
I think if you use get('%'), it will read in everything up to the '%'.