Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Variable problem in C++


ghost's Avatar
0 0

Hi!

How do i do if I want to give a variable a value consisting of some text and a variable? Like

string hello, ip = 127.0.0.1; hello = "PING "+ip;

Or if I want to run the system command with both text and a variable like

string ip = 127.0.0.1; system("PING"+ip);

Sry if I wrote something wrong, I'm kinda new to this… Please help me :)

Thx


alfredwolf's Avatar
Member
0 0

you could use the system commands like

system(ping 127.0.0.0); and loop it if your trying to attempt a ping of death.

or

#include <iostream>

int main() { int counter; std::cout << "How many times to ping?: "; std::cin >> counter; while (counter > 0) { system("Ping 127.0.0.0"); counter–; } std::cout << "you pinged: " << counter << "\n"; system("PAUSE"); return 0; }

of couse where the ip = 127.0.0.0 you might wanna change to the one your pinging


Uber0n's Avatar
Member
0 0

I think that was just an example… Is there a way to combine a text string and a variable and turn it into a new variable?

Not just using PING… But in general :right:


alfredwolf's Avatar
Member
0 0

yeah… but i havent done much of that you'll wanna check out polymorphisim or something else…… just a though.