Problem with string Array

Hey guys , i am having a problem with string arrays. Basically ,i declared my array in the header file. Here is my prog.


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

   Main.cpp
 

      using namespace std;
 

      int main(){
    string Test = "fat";
 
      e te;

      te.b(Test);
 
      }
  
.
      Test.h

      class e
 
      {
.
      public:
 
      void b(string)

      string a [ ];
  
      int f;

       
     };

      Array.cpp
  
      void e::b (string t)
    {
 
      e rt;
      rt.f ++;
 
      rt.a[rt.f] = t;
      cout << rt.a[rt.f] << endl;
      }


Okay guys , when i tried this using Netbeans on Windows running on MinGW. But when i tried it on Netbeans in Unix or just compiling using g++ using text editor , i kept on getting segmentation error. I hope for some help regarding this matter.
Line 28 is definitely not right.
You should remember that string already contains an array (of char to be precise). The size of the internal array in the std::string class is automatically adjusted when characters are assigned or appended to the string. You do not have any direct access to this internal array. assign, append, push_back, operator= and many more similar methods are provided in the class to modify the content of the string.

Refer to http://www.cplusplus.com/reference/string/string/
Topic archived. No new replies allowed.