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.
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.