![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
#1 |
20th Level Warrior
![]() Join Date: December 28, 2003
Location: Kentucky
Age: 39
Posts: 2,820
|
So, I have this program that I am working on for CS 115... it's a C++ program that needs to read in a string from the user and then create a file to output to that goes by that name...
Anyone familiar with that? I'm having trouble getting my string prompt to work, and I have no idea how to get that string to become a filename... With the string prompt, right now, I have the following (with the irrelevant stuff cut out). Note that the double angle-brackets have been replaced by ,, so that the board can display the text. string filename; cout ,, "Enter a filename for the charts: "; cin.getline ( cin, filename ) ; I am including the < string > library. [ 10-13-2005, 12:43 PM: Message edited by: Ilander ]
__________________
Is that what you really want to say? |
![]() |
![]() |
![]() |
#2 |
Emerald Dragon
![]() Join Date: February 6, 2003
Location: Norway
Age: 39
Posts: 928
|
I don't really have any C++ experience, but hey [img]tongue.gif[/img] (this just what I gather from some examples on some site, so might be terribly wrong)...
Try using "getline (cin, filename);" To open a file with that name for writing: ofstream outfile (filename); Write to file with: outfile ,, (something); Close file with: outfile.close(); outfile can be named something else, obviously. Think you should be including < fstream > for ofstream to be working. And, ifstream is used for reading from files [ 10-13-2005, 02:10 PM: Message edited by: Gnarf ]
__________________
I want a hippo. |
![]() |
![]() |
![]() |
#3 |
20th Level Warrior
![]() Join Date: December 28, 2003
Location: Kentucky
Age: 39
Posts: 2,820
|
Whoohoo! It was indeed getline (cin, filename) and not cin.getline (cin, filename) as I thought...
On to working with the files...and yeah, I'm including < fstream > I'll update as soon as I work out the file output stuff as to how I did it. Thanks, Gnarf. EDIT: Now, the problem is adding the suffix .txt to the output file...everything works fine except for that. My main problem with creation of the file appears to have been type coercion...I was using a "new" string in place of an "old" string. I converted between the two using .c_str() . So, now, I have the following to create the file: ofstream plots; *prompt for file name, store as "filename,"* plots.open(filename.c_str()); but this creates a file with no suffix...It compiles, but it is useless. Any help would be greatly appreciated. [ 10-13-2005, 03:41 PM: Message edited by: Ilander ]
__________________
Is that what you really want to say? |
![]() |
![]() |
![]() |
#4 |
Emerald Dragon
![]() Join Date: February 6, 2003
Location: Norway
Age: 39
Posts: 928
|
filename = filename + ".txt";
(after getting filename from user and before opening the file) Should do, I'd guess.
__________________
I want a hippo. |
![]() |
![]() |
![]() |
#5 |
20th Level Warrior
![]() Join Date: December 28, 2003
Location: Kentucky
Age: 39
Posts: 2,820
|
Indeed, that does seem to work
![]() I feel very much like a physics major who's out of their depth in programming...but I freakin' love this stuff...even when I am confronted with stuff like this that I really should have figured out. Thank you, Gnarf.
__________________
Is that what you really want to say? |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Technical Difficulties | Bithron | General Discussion | 7 | 11-09-2006 02:50 AM |
Technical Difficulties | Druzil | Icewind Dale | Heart of Winter | Icewind Dale II Forum | 9 | 06-04-2004 06:05 PM |
Technical Difficulties | KittyGal | Baldurs Gate II Archives | 15 | 06-19-2001 11:47 AM |
Mechanical Difficulties | rngamer | Wizards & Warriors Forum | 4 | 12-30-2000 04:04 AM |
Level Up difficulties | Scribner | Wizards & Warriors Archives | 7 | 10-03-2000 11:39 AM |