简体   繁体   English

如何防止我的程序打印多余的斜线?

[英]How do I prevent my program from printing an extra slash?

while (stack.is_not_empty()) {
  cout << "/" << stack.pop();
}

Ideally, my output should be: /feb/12/1983 理想情况下,我的输出应为:/ feb / 12/1983

but I'm getting: //feb/12/1983 但我得到:// feb / 12/1983

I don't understand how this could possible print two slashes in the beginning. 我不知道这怎么可能在一开始就打印两个斜杠。 There is no other code that prints out anything else out. 没有其他代码可以打印出其他任何内容。

Have you checked the values that are in the stack? 您是否检查了堆栈中的值? If you print them out one per line you might find an unexpected value such as an empty string. 如果将它们每行打印一次,则可能会发现意外的值,例如空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM