我正在检查字符串表示是否等于给定的整数。我打算在一个函数中使用stringstream。我也有一个operator=
。尝试使用stringstream将字符串转换为int
我有点困惑如何一起执行这些,如果我失去了一些东西。这是我的最后一项任务,这只是我整个计划的一小部分。在这方面我找不到很多指导,我感觉他们都指导我atoi或atod,这是我不允许使用的。
#ifndef INTEGER
#define INTEGER
using std::string;
class Integer
{
private:
int intOne;
string strOne;
public:
Integer() {
intOne = 0;
}
Integer(int y) {
intOne = y;
}
Integer(string x) {
strOne = x;
}
void equals(string a);
Integer &operator=(const string*);
string toString();
};
#endif
在这个头文件中,我不确定什么参数我用= =运算符。
#include <iostream>
#include <sstream>
#include <string>
#include "Integer.h"
using namespace std;
Integer &Integer::operator=(const string*)
{
this->equals(strOne);
return *this;
}
void Integer::equals(string a)
{
strOne = a;
toString(strOne);
}
string Integer::toString()
{
stringstream ss;
ss << intOne;
return ss.str();
}
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <string>
#include <ostream>
using namespace std;
#include "Menu.h"
#include "Integer.h"
#include "Double.h"
int main()
{
Integer i1;
i1.equals("33");
cout << i1;
}
对不起,如果它的一个坏问题我不太熟悉这种类型的任务,并会采取任何帮助,我可以得到。谢谢。