C++ -- New line seen in command prompt but the same string is seen with \n in file output : I have this code which runs fine 

    #include <iostream>
    #include <set>
    #include <sstream>
    
    int main()
    {	
    	std::set<std::string> a;
    	a.insert("foo");
    	a.insert("bar");
    	a.insert("zoo");
    	a.insert("should");
    	a.insert("work");
    	std::stringstream b;
    	std::set<std::string>::iterator it;
    	for (it = a.begin(); it != a.end(); it++)
    	{
    		b << " " << *it <<"," <<"\n";
    		
    	}
    	
    	std::string aaa = b.str();
    	std::cout <<aaa;
    }
**Output in command prompt:**

    bar, //new line after ","
    foo, //new line after ","
    should,
    work,
    zoo,

If I try to write the same string aaa in file I am expecting the same output to get print in the file i.e. every string after "," in new line, rather I am getting output in my file as follows (In single line with \n):

    " bar,\n foo,\n should,\n work,\n zoo,\n"


Can anyone help me with this?
Thanks.