在我下面的代码中,我想循环直到用户提供正确的输入。但是当我尝试时,它变成了一个不间断的循环。
Please Enter Valid Input.
如果没有 while 循环,它也是一样的。
这里有while循环:
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <sstream>
using namespace std;
class library {
public:
library() {
int mainOption;
cout<<"Please choose the option you want to perform."<<endl;
cout<<"1. Member Section"<<"\n"<<"2. Books, Lending & Donate Section"<<"\n"<<"3. Returning Section"<<endl;
bool option=true;
while (option==true) {
cin>>mainOption;
if (mainOption==1) {
cout<<"section 1"<<endl;
option=false;
} else if (mainOption==2) {
cout<<"section 1"<<endl;
option=false;
} else if (mainOption==3) {
cout<<"section 1"<<endl;
option=false;
} else {
cout<<"Please …Run Code Online (Sandbox Code Playgroud) 我有一个从文本文件中删除数据的功能.
输入有效输入时遇到问题:
else按预期执行该部分if和else部分.这是我的代码:
void Member::processTransaction()
{
fstream f;
f.open("Member.txt",ios::in|ios::out);
int x = 0, y = 0, z = 0;
while (!f.eof())
{
f >> idList[x] >> nameList[y];
if (id == idList[x])
{
cout << idList[x] << "\t" << nameList[x] << endl;
cout << "Do you want to delete the entry (Y/N) : " << endl;
char deleteEntry = getche();
if(deleteEntry=='Y'||deleteEntry=='y')
deleteInformation();
f.close();
}
else
{
cout << "No Matches Found!";
}
} …Run Code Online (Sandbox Code Playgroud) 我有这样的字符串值: 2014-04-14
我想将此转换为Integer 20140414
我知道字符串输入到Integer可以这样做
std::string myString = "45";
int value = atoi(myString.c_str()); //value = 45
Run Code Online (Sandbox Code Playgroud)
但我不知道如何删除-标志.