-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