J
justyb11
Hello. I'm trying to use the following code but I continue to get
Aborted as the output.
Please note that this is compiled using gcc 3.3.4 on Linux 2.6.11.11
---
//file: vectest.cc
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
struct foo_node {
std::string first_name;
std::string last_name;
foo_node() : first_name("John"), last_name("Doe") {}
foo_node(std::string a, std::string b) : first_name(a), last_name(b)
{}
~foo_node() {}
void operator=(const foo_node& o) { first_name = o.first_name;
last_name = o.last_name; }
}
int main() {
std::vector<foo_node> aList;
for(int x=0;x<25;x++) {
char *str;
sprintf(str, "Person%d", x);
std::string m1(str);
sprintf(str, "LastName%d", x);
std::string m2(str);
foo t1(m1, m2);
aList.push_back(t1); //<---- This is where the
program stops.
}
std::vector<foo_node>::iterator iterList;
for(iterList=aList.begin(); iterList != aList.end(); iterList++)
std::cout << iterList->first_name << "/n" << iterList->last_name
<< std::endl;
return 0;
}
//End of vectest.cc
--------------
First I know I could have used 'using namespace std' to make some of
this a lot more readable. I'm sorry about that, but this is the code
copied and pasted.
So I was wondering why it keeps giving me 'Aborted' as the output and
what I can do to correct this code.
Thank you in advance,
Justin
Aborted as the output.
Please note that this is compiled using gcc 3.3.4 on Linux 2.6.11.11
---
//file: vectest.cc
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
struct foo_node {
std::string first_name;
std::string last_name;
foo_node() : first_name("John"), last_name("Doe") {}
foo_node(std::string a, std::string b) : first_name(a), last_name(b)
{}
~foo_node() {}
void operator=(const foo_node& o) { first_name = o.first_name;
last_name = o.last_name; }
}
int main() {
std::vector<foo_node> aList;
for(int x=0;x<25;x++) {
char *str;
sprintf(str, "Person%d", x);
std::string m1(str);
sprintf(str, "LastName%d", x);
std::string m2(str);
foo t1(m1, m2);
aList.push_back(t1); //<---- This is where the
program stops.
}
std::vector<foo_node>::iterator iterList;
for(iterList=aList.begin(); iterList != aList.end(); iterList++)
std::cout << iterList->first_name << "/n" << iterList->last_name
<< std::endl;
return 0;
}
//End of vectest.cc
--------------
First I know I could have used 'using namespace std' to make some of
this a lot more readable. I'm sorry about that, but this is the code
copied and pasted.
So I was wondering why it keeps giving me 'Aborted' as the output and
what I can do to correct this code.
Thank you in advance,
Justin