D
DeveloperDave
Hi,
I am trying to improve some code that I currently have.
I have a simple class called RequestMessage e.g.
class RequestMessage
{
public:
RequestMessage();
~RequestMessage();
string& getMessage()
private:
string origin
string type;
string body;
....
....
string rqstMessage;
};
getMessage formats the private members and stores them in rqstMessage
before returning a reference to it.
string&
RequestMessage::getMessage()
{
ostringstream* message = new ostringstream("Orgin: ");
message << origin << endl;
message << "Type:" << type << endl;
message << "Body: << body << endl;
rqstMessage = message->str();
return rqstMessage;
}
The problem I have, is that I don't like the fact I already have
stored my data in strings, and then use another string to store it all
again in a formatted way.
Is there a better way to do this, without using the additional memory?
Cheers
I am trying to improve some code that I currently have.
I have a simple class called RequestMessage e.g.
class RequestMessage
{
public:
RequestMessage();
~RequestMessage();
string& getMessage()
private:
string origin
string type;
string body;
....
....
string rqstMessage;
};
getMessage formats the private members and stores them in rqstMessage
before returning a reference to it.
string&
RequestMessage::getMessage()
{
ostringstream* message = new ostringstream("Orgin: ");
message << origin << endl;
message << "Type:" << type << endl;
message << "Body: << body << endl;
rqstMessage = message->str();
return rqstMessage;
}
The problem I have, is that I don't like the fact I already have
stored my data in strings, and then use another string to store it all
again in a formatted way.
Is there a better way to do this, without using the additional memory?
Cheers