문자열 표현이 주어진 정수와 같은지 확인하려고합니다. 나는 함수 안에서 이것을 위해 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;
}
죄송합니다. 좋은 질문이 아니신 경우이 유형의 과제에 너무 익숙하지 않으며 도움을받을 수 있습니다. 감사.