-5
我有我的类复杂:如何从C++文件创建对象?
#include "Complejo.h"
#include <sstream>
Complejo::Complejo() {
// TODO Auto-generated constructor stub
real = 0;
imaginary = 0;
}
Complejo::Complejo(int a, int b){
real = a;
imaginary = b;
}
Complejo::~Complejo() {
// TODO Auto-generated destructor stub
}
std::string Complejo::mostrar()const{
std::stringstream s;
s << real << "+" << imaginary <<"i";
return s.str();
}
在我main
我需要读取一个文件(每行有一个复杂的)是这样的:
3 + 5I
4 + 2I
3 + 3i
并创建对象。我怎样才能做到这一点?
您正在寻找[Seraialization](https://en.wikipedia.org/wiki/Serialization)。还要考虑用英文编写代码。我不知道* Complejo *是什么,或者* mostrar *。 – IInspectable
“Complejo”表示“复杂”,“mostrar”表示“显示”@IInspectable – stackptr