|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
fstream file variable?
Is there a way to have the user specify what he wants the file to be called that he is creating and appending to? For example...
string filename; ofstream blah; cout << "file name?\n"; cin >> filename; blah.open("filename.txt",ios::app); but instead of "filename.txt" it has whatever the user typed in and then ".txt" Thanks. -andy
__________________
hmmm... |
|
#2
|
||||
|
||||
|
Have you tried this:
blah.open(filename.c_str(),ios::app); |
|
#3
|
||||
|
||||
|
Well I'll be..
Thanks man..but how do I get a .txt at the end of that baby on the same line?EDIT: I concactinated (however you spell that word) it with another string with a value of ".txt" It worked but im hoping i can add it on the same line as the variable. Last edited by andy3109 : May 14th, 2003 at 06:01 PM. |
|
#4
|
||||
|
||||
|
Either:
filename += ".txt"; blah.open(filename.c_str(),ios::app); or: blah.open(string(filename + ".txt").c_str(), ios::app); or even: blah.open((filename + ".txt").c_str(), ios::app); Take your pick! |
|
#5
|
||||
|
||||
|
scorp..have I ever told you i loved you? (in a non-gay way)
THANKS MAN! -andy |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > fstream file variable? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|