Er, when you post code make sure to place it between 'code' blocks, like this:
[code]
std::cout << "Hello, world!" << std::endl;
[/code]
which looks like this:
std::cout << "Hello, world!" << std::endl;
I assume thatfilename is a std::string and outdata is a std::ostream. The stream classes are meant for parsing data, not pure string input. Instead, say:
std::getline( std::cin, filename );
if (filename.empty()) filename = "newfile.txt";
outdata.open( filename.c_str() );
A very useful website is http://www.cppreference.com/
Hope this helps.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
It isn't working because you have not obeyed my advice. The user can hit enter a zillion times and it won't make any difference as long as you are using cin >> newfile; .
Also, notice how most of the lines you have written are exactly the same. Put all the stuff that writes to file by itself,once, after the file is opened using your if...else statement.
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229