Because when you merge the files you are reading only one word at a time with "w1 >> s" not the whole line and then writing one word with a "\n" at the end.
If you use "<string>" instead of "<string.h>" it would be easier to use std::getline(w1, line)" and then write "line" to the new file. I imagine you could do the same with "w1.getline(...)", but I am not that familiar with that version.
> some one please run my code and tell why each word is in different line
> instead of every line being in different line
It is not necessary to run your code to tell you why it is so.
1 2 3 4
while(w1>>s) // for each word in w1
newfile<<s<<"\n"; // write that one word followed by a new line
while(q1>>s) // for each word in q1
newfile<<s<<"\n"; // write that one word followed by a new line
Use getline() if you want to read a complete line.