Greetings All

Hi all,

Noob here. Trying to understand pointers in conjunction with stringstreams. When I try to access the str() from my strinstream pointer it will not work. My code is below. Compiler error: error: request for member ‘str’ in ‘ss’, which is of non-class type ‘std::stringstream* {aka std::basic_stringstream<char>*}’

Thanks, -AR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

void writestream(stringstream *ss){
  cout << *ss.str();
}

int main(){
  stringstream s;
  s << "Hello World" << endl;
  writestream(&s);
  return 0;
}
The . operator has higher precedence than the * operator. You can write :
cout << (*ss).str();. But in C and C++ you can write this in a shorter form : ss->str().
Thank you sir... After some years of dealing of higher level languages I can see it's going to take some getting used to with C++ syntax/parsing rules. Thanks again.
hehe, what do you, sir, exactly mean by higher level languages exactly?? The last time I checked, C++ was still a high level language..
>The last time I checked, C++ was still a high level language..

Point taken. ;)

Topic archived. No new replies allowed.