Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

newb question....

Name: Anonymous 2006-04-11 18:08

Check this c++ code:

    string file_opened ("lol.txt");
    ofstream communism;
    communism.open (file_opened);

The thing keeps writing to a file called file_opened rather than lol.txt.  How do I get the thing to treat the variable as the string that makes it up?  Tutorials say nothing about this...  They always just show you how to write strings directly to output.

Also, while I'm at it, (I suspect this is related) if I wanted to generate the names of variables using code, how would I do it?  Say I wanted to initialize ten variables, name1 - name10, but I didn't feel like typing out every one.  Here's what I would write intuitively: 

while (i < 9)  {
    i+=1;
    int namei;
};

But I know this isn't right.

Name: Anonymous 2006-06-03 10:28

>>23 I guess so but then there is the problem of implicit conversions everywhere. Using a method to convert to char * might make more sense because it makes the conversion obvious.

I've always been fucked up about conversions though:
string meme = "NO U";
char *str = meme.c_str();
This looks wrong ya? But it's not! We're accessing the meme through the pointer.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List