Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loops

Status
Not open for further replies.

3li773

Programmer
Jan 23, 2003
20
0
0
CA
hi

im new to C++ and I used python before.

now in python i could make a script like this

print "hello"
while True:

cmd=raw_input(">")

if cmd == "hello"
do something

else
do something else

now that code repeats the input part and i wanted to know how I would go about that in C++

thnx
 
you should also define cmd as a string and you'll need to include the <string.h> header file, then you can put:

#include <iostream>
#include <string.h>

int main()
{
BOOL something=TRUE
while(something==TRUE)
{
string cmd;
cin>>cmd;
if(cmd==&quot;hello&quot;)
{
do something
}
else
{
do something else
}
}
return 0;
}
 
Thank you both vary much for the help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top