Segmentation fault: class of string

U

unlexx

Hello. Why? :)
class mA
{
public:
int Id;
int gr_id;
string ppatch;
double p;
mA():ppatch("123"){};//initializing the variables
};
int main()
{
int counter=300;
//...
mA *pma = new mA[counter-1];
while (counter--){
pma[counter].gr_id=100; //ok
pma[counter].ppatch="1"; //fault
// pma[counter].ppatch.assign(str, 0, str.length()); //fault
// std::cout << pma[counter].ppatch.c_str()<< std::endl; //fault ???
}
}
 
S

SG

int counter=300;
mA *pma = new mA[counter-1];
while (counter--){
pma[counter].gr_id=100; // ok
pma[counter].ppatch="1"; // fault
}

Try
mA *pma = new mA[counter];

or better yet: std::vector<mA>

Cheers!
SG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top