- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试用 C++ 读取一个文件。我向用户询问文件名,如果文件存在我打开它但如果它不存在我一直询问直到输入有效的文件名。但是,当用户首先输入错误的文件时,即使输入了有效的文件名,我的程序也会将其识别为错误。这是我的代码:
ifstream input;
string filename;
cout<<"Enter the file name";
cin>>filename;
input.open(filename.c_str());
while(input.fail())
{
cout<<"Incorrect filename, please enter again";
cin>>filename;
input.open(filename.c_str());
}
有人可以帮忙吗?谢谢
最佳答案
输入错误需要清空输入。试试这个:
ifstream input;
string filename;
cout<<"Enter the file name";
cin>>filename;
input.open(filename.c_str());
while(input.fail())
{
input.clear();
cout<<"Incorrect filename, please enter again";
cin>>filename;
input.open(filename.c_str());
}
关于c++ - 要求一个输入文件,直到它在 C++ 中是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16586259/
我需要在 JavaScript 中的笛卡尔坐标和球坐标之间进行转换。我在论坛上浏览了一下,没有找到我要找的东西。 现在我有这个: this.rho = sqrt((x*x) + (y*y) + (z*
有没有matrix3d可以像这样把矩形变成梯形的?我知道常规的 2d 矩阵变换只能以平行四边形结束,因为您只能有效地倾斜和旋转。 div { width: 300px; height:
关于这个例子(d3.j radial tree node links different sizes),我想知道是否可以在 d3.js 中混合径向树和直线树。 对于我的 jsFiddle 示例:htt
我尽量把标题写得最好,但我不确定如何准确描述这里发生的事情,所以请随时更正。 我想使用 › 直 Angular 引号 (›) 而不是 > 直 Angular 引号 (>),虽然 › 字符比 > 短,但
我正在尝试使用 CSS 创建一个具有圆边的矩形棱柱,如下图所示。 到目前为止,我已经指定了顶部和底部的边界半径。问题是我不知道如何让另一边的左右边缘向内 curl 。因此,拐 Angular 处不应有
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 去年关闭。 社区去年审查了是否重
首先,我刚刚开始学习 HTML 和 CSS。 我想如何使用这段代码: https://codepen.io/martinjkelly/pen/vEOBvL .container { width:
我是一名优秀的程序员,十分优秀!