如何在 C++ 中用 scanf("%d # %d",&a,&b);
实现类似 cin
的效果?
最佳答案
您可以通过将 #
提取到一个字符中来跳过它:
std::istringstream iss("10 # 20");
int main()
{
int a, b; char hash;
iss >> a >> hash >> b;
assert(a == 10 && b == 20);
}
关于c++ - 使用 cin 跳过预期的字符,如 scanf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59428895/