# String class for g++ under OSX?



## Kinniken (Oct 6, 2003)

Hi, does anyone know if a string class similar to the one available for many UNIX (AIX in my case) exists for the mac?
I have a university project based on it I need to work on at home, and without the class I'm stuck.
And no, I can't redo it with pointers 

TIA,

Kinniken


----------



## cfleck (Oct 6, 2003)

as far as i know it is "built in" with g++.  you just need to do a #include <string>

you probably need to add a "using namespace std or else use the full qualifier.  your c++ file might look like this...


```
#include <iostream>
#include <string>
 
using namespace std;

int main(){
  string s = "happy happy";

  cout << s << endl;
}
```


----------



## Kinniken (Oct 6, 2003)

Thanks! That was indeed it. My test program (very similar to yours) now work. 
However, I have an other strange mistake I did not get using g++ at University:

the line (in a .C):

_void Parseur :: parse (const string & fname) {_

where Parseur is a custom class, gives me the following error:

_Parseur.C:9: parse error before `&' token_

Any ideas?

TIA,

Kinniken


----------



## cfleck (Oct 6, 2003)

i'm shooting in the dark, but here is my best effort.  

i'm assuming that you have this function declaration and the function implementation seperate.  my only guess is that you are passing have it as pass by reference (&) in one spot and not the other.  thats all i've got for you though.  good luck.


----------



## Kinniken (Oct 6, 2003)

Nope, that's not it. I checked, the declaration and implementation are the same, and anyway the error message does not fit. Good attempt 
Well, you solved my first problem (and thanks, I doubt I would have thought of that), I'll try to solve this myself.

Kinniken


----------



## anarchie (Oct 7, 2003)

For Project Builder, your file extension should be .cpp or .cp if you use C++ features in that file.


----------

