Visit the Ironworks Gaming Website Email the Webmaster Graphics Library Rules and Regulations Help Support Ironworks Forum with a Donation to Keep us Online - We rely totally on Donations from members Donation goal Meter

Ironworks Gaming Radio

Ironworks Gaming Forum

Go Back   Ironworks Gaming Forum > Ironworks Gaming Forums > General Discussion
FAQ Calendar Arcade Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 10-13-2005, 12:43 PM   #1
Ilander
20th Level Warrior
 

Join Date: December 28, 2003
Location: Kentucky
Age: 38
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?
Ilander is offline   Reply With Quote
Old 10-13-2005, 02:09 PM   #2
Gnarf
Emerald Dragon
 

Join Date: February 6, 2003
Location: Norway
Age: 38
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.
Gnarf is offline   Reply With Quote
Old 10-13-2005, 02:45 PM   #3
Ilander
20th Level Warrior
 

Join Date: December 28, 2003
Location: Kentucky
Age: 38
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?
Ilander is offline   Reply With Quote
Old 10-13-2005, 04:01 PM   #4
Gnarf
Emerald Dragon
 

Join Date: February 6, 2003
Location: Norway
Age: 38
Posts: 928
filename = filename + ".txt";

(after getting filename from user and before opening the file) Should do, I'd guess.
__________________
I want a hippo.
Gnarf is offline   Reply With Quote
Old 10-13-2005, 04:16 PM   #5
Ilander
20th Level Warrior
 

Join Date: December 28, 2003
Location: Kentucky
Age: 38
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?
Ilander is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved