1.不用goto语句的情况下可以用下面的方法。
#include<stdio.h>
#include<conio.h>
int main(void)
{
bool b = true;
while(b)
{
char ch;
printf("Inputacharacter:");
ch = getch();
if(ch==1)
{
b = false;
}
else
{
printf("\nYouinputa'%c'\n",ch);
}
}
return 0;
}
如果是字符串的话,请用下面的代码:<pre class="cpp" name="code"> #include <iostream>
using namespace std;
void main()
{
bool b = true;
while(b)
{
char s[50];//字符数组,用于存放字符串的每一个字符
cout<<"Please input a string"<<endl;
cin>>s;//注意cin.get(s,50);cin.get()是保留回车在输入流队列中的.而cin是丢弃回车的.
if(strcmp(s , "123") == 0)
{
b = false;
}
else
{
cout<<"The string you input is:"<<s<<endl;
}
}
}