 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chris Guest
|
Posted: Sun Aug 13, 2006 9:10 am Post subject: segmentation fault |
|
|
I'm compiling the following code with GCC 4.1.0 (on fedora 6 I think).
It compiles fine, then when I run it it simply prints "segmentation
fault".
int main() {
vector<vector<string> > yo;
yo[0][0] = "hello";
cout << yo[0][0];
return 0; }
1. What's causing this?
I'm using the object "vector<vector<string> >" so I can split a string
into lines, then split the lines into words so that
"hello there\nTommy Boy"
becomes
[ ["hello", "there"], ["Tommy", "Boy"] ]
2. Should I do this a different way?
Thanks for any help! |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Sun Aug 13, 2006 9:10 am Post subject: Re: segmentation fault |
|
|
Chris wrote:
| Quote: | I'm compiling the following code with GCC 4.1.0 (on fedora 6 I think).
It compiles fine, then when I run it it simply prints "segmentation
fault".
int main() {
vector<vector<string> > yo;
yo[0][0] = "hello";
cout << yo[0][0];
return 0; }
1. What's causing this?
Surely this must be an FAQ by now, if not, look back though the past |
week or so of postings. You can't use operator [] on an empty vector.
--
Ian Collins. |
|
| Back to top |
|
 |
Jim Langston Guest
|
Posted: Sun Aug 13, 2006 9:10 am Post subject: Re: segmentation fault |
|
|
"Chris" <chrispatton (AT) gmail (DOT) com> wrote in message
news:1155444123.919593.158580 (AT) m79g2000cwm (DOT) googlegroups.com...
| Quote: | I'm compiling the following code with GCC 4.1.0 (on fedora 6 I think).
It compiles fine, then when I run it it simply prints "segmentation
fault".
int main() {
vector<vector<string> > yo;
yo[0][0] = "hello";
cout << yo[0][0];
return 0; }
1. What's causing this?
I'm using the object "vector<vector<string> >" so I can split a string
into lines, then split the lines into words so that
"hello there\nTommy Boy"
becomes
[ ["hello", "there"], ["Tommy", "Boy"] ]
2. Should I do this a different way?
Thanks for any help!
|
Your yo vector is empty. You need to insert into it before you can use it.
std::vector mama;
mama.push_back( "hello" );
yo.push_back( mama ); |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|