I need to merge same words from f.txt and n.txt to f1.txt but i only cant merge them when every word is on its own line and in one line, like it only compares 1st to 1st, 2nd to 2nd, and so on, how to make it look through all text and merge them?
Then you'll probably want to read one of the files, extracting the words into some kind of container, vector, map, etc. Then read a word from the second file, search your container to see if the word is contained in your container, if it is you would write the word into the third file.
Store the words from each file in a set<string>, then find the intersection using set_intersection().
You can use f >> s to read words. Do this with a loop.
Once you have a word (inside the loop), strip it of all non-alphanumeric characters and convert all uppercase letters to lowercase. Use a loop. (Create a function to do it.)
Also create a function to read a file's words into a set. Once you have the two sets (one for each file), intersect them into a third set. The third set will contain the words you should output.