Concatenating string* pointers!! Help

i have a class with :
std::string* aaa;
std::string* bbb;
std::string* outputString;
int number1;
int number2;

and i need to write a method std::string* displayoutputString();,
which returns a pointer std::string* outputString; - which points to a string that is equal aaa+bbb+number1+number2.
so, i dont know how to concatenate all string and ints to one string
please help me to write that method!!
Last edited on
Use a stringstream.

However...why do you need to use pointers here? From here, it seems like a waste of time.
i know its stupid, but that is my assignment ))
can you give me example how to do that please! =)
Check out the reference section. I can't really help you if you don't have any code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <sstream>
#include <iostream>

using namespace std;


string* displayOutputString() {
  string *aaa = new string("aaa");
  string *bbb = new string("bbb");
  int number1 = 10;
  int number2 = 20;
  stringstream temp;
  if (aaa) temp << *aaa;
  if (bbb) temp << *bbb;
  temp << number1 << number2;
  return new string(temp.str());
}

int main() {
  string* res = displayOutputString();
  if (res) {
    cout << *res << "\n";
    delete res;
  }

  return 0;
}

Thanks a lot sohguanh!! it works just perfect !
Topic archived. No new replies allowed.