How can I create object from a file in C++?

You can do it like this for each line:

void Complejo::f(const std::string& line)
  std::stringstream  s(line);

You can add checks for a legit line etc.

BTW: the mostrar function should be able to print negative values like: -1-1i, therefore it can be:

std::string Complejo::mostrar()const{
    std::stringstream  s;
    s << real << (imaginary >= 0) ? "+" : "" << imaginary <<"i";
    return s.str();

Browse More Popular Posts

Leave a Comment