Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can list container contain an vector object, such as list< vector<string> >??

Reply
Thread Tools

Can list container contain an vector object, such as list< vector<string> >??

 
 
ehui928
Guest
Posts: n/a
 
      05-29-2006
hi, everybody
I am a newbie in STL. When I compile the following program under
gcc4.0, I got a the following errors.
I wonder whether the form of list< vector<string> > is correct in STL
?
// test.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <list>

using namespace std;

typedef vector<string> RECORD;
typedef list< RECORD > DataInstances;

DataInstances getRecords(const string& filename);
void print_data(const DataInstances& d);
void print_vector(const vector<string>& s);

const string filename = "mydata";

int main(void)
{
DataInstances data;

data = getRecords(filename);
print_data(data);

return 0;
}

DataInstances getRecords(const string& filename)
{
.......
return instances;

}
void print_vector(const vector<string>& s)
{
......
}

void print_data(const DataInstances& d)
{
DataInstances::iterator pos;
// the compiler seems to say "pos = d.begin()" is error? why
?
for (pos = d.begin(); pos != d.end(); ++pos) { //test.cpp:86
,complier say this line has error
print_vector(*pos);
}
}

Following is the compile errors:

In function 'void print_data(const DataInstances&)':
test.cpp:86: error: no match for 'operator=' in 'pos = (+
d)->std::list<_Tp, _Alloc>::begin [with _Tp =
std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >, _Alloc =
std::allocator<std::vector<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > >]()'
/usr/lib/gcc/i386-redhat-linux/4.0.2/../../../../include/c++/4.0.2/bits/stl_list.h:112:
note: candidates are:
std::_List_iterator<std::vector<std::basic_string< char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > >&
std::_List_iterator<std::vector<std::basic_string< char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > >:perator=(const
std::_List_iterator<std::vector<std::basic_string< char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > > >&)


Any one give me some help ?
Thanks!

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      05-29-2006
ehui928 wrote:

> hi, everybody
> I am a newbie in STL. When I compile the following program under
> gcc4.0, I got a the following errors.
> I wonder whether the form of list< vector<string> > is correct in STL
> ?


It is.

> // test.cpp
> #include <iostream>

[snip]
>
> void print_data(const DataInstances& d)
> {
> DataInstances::iterator pos;
> // the compiler seems to say "pos = d.begin()" is error? why
> ?


You try to obtain an iterator to a const container. Try const_iterator.

> for (pos = d.begin(); pos != d.end(); ++pos) { //test.cpp:86
> ,complier say this line has error
> print_vector(*pos);
> }
> }

[snip]


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
ehui928
Guest
Posts: n/a
 
      05-29-2006
OK, now it works!
Thank you very much!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RCR: String#contain? and Array#contain? Roger Pack Ruby 3 09-28-2010 04:13 PM
Does string contain A, and if so, does a section of string contain B Jason Carlton Javascript 11 12-08-2009 06:07 PM
size vs. capacity in a container, such as vector puzzlecracker C++ 4 10-14-2008 07:29 AM
can a container contain references? Jess C++ 6 05-09-2007 05:53 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM



Advertisments