using a variable inside quotes or some other easier way

  • cantrell
  • Born
  • Born
  • cantrell
  • Posts: 1

Post 3+ Months Ago

Hey does anyone know how to make a variable express its value inside a quote in C++;

for example i have a function that opens up a set of files that varies from:
time0 to time1000 by tens...so time0, time10, time20, time30.....with the number representing what time step the program is on. So right now i have:
Code: [ Select ]
if (i == 0) {
fout.open("time0.txt");
}
  1. if (i == 0) {
  2. fout.open("time0.txt");
  3. }


and so on (not for all 1000 cause that would suck)

but i know there is a way to make it into one line like:
Code: [ Select ]
if (i % 10 == 0) {
fout.open("time\$i.txt");
}
  1. if (i % 10 == 0) {
  2. fout.open("time\$i.txt");
  3. }


but i dont know how to make the "i" represent the number that is being stored there. when I do the thing above I get a file named "time$i.txt" that has been written in 100 times.

there is probably also a way to do something like:
Code: [ Select ]
char bob[] = "time" + i + ".txt";
if (i%10 == 0) {
fout.open(bob);
}
  1. char bob[] = "time" + i + ".txt";
  2. if (i%10 == 0) {
  3. fout.open(bob);
  4. }

but i cant seem to get that to work either.

any help would be greatly appreciated
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Welcome to Ozzu Cantrell :)

Two things,
1 : Please remember to use either
Code: [ Select ]

or
PHP Code: [ Select ]
 
tags when posting code. (I fixed your original post)

2 : Please post new topics in the appropriate forum.

//Moved
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Code: [ Select ]
for(i = 0; i < 1000; i + 10)

i think its something like that

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.