我的主要功能
int main(){
Postfix post;
char size=100;
char infix[size];
string get_input=" ";
cout<<"Input Infix";
cin>>infix;
int size=strlen(infix);
char postfix[size];
post.infix_to_postfix(infix, postfix, size);
cout<<"\nInfix Expression is:"<<" "<<infix;
cout<<"\nPostfix Expression is:"<<" "<<postfix;
cout<<endl;
该程序使用堆栈将中缀表示法转换为后缀表示法。我的问题是,有没有办法继续循环,直到用户不想为止。 与此类似
int n;
cin>>n;
while (n!=0){
// keep doing whatever
}
最佳答案
以下是您可以执行此操作的两种方法..
首先是建议使用 std::string
它会让你的生活变得轻松。尝试将其纳入您的编码习惯中..
while (std::getline(std::cin, line) && !line.empty())
{
//write your logic here
}
要打破循环,用户必须按enter
第二种方式
std::string str;
while(std::cin>>str)
{
//write your logic here
}
要中断循环,请按 ctrl+D
关于c++ - 继续运行程序直到用户输入退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33249215/