Main.cpp
usingnamespace 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.
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.