473,544 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(cons t string& filename);
void print_data(cons t DataInstances& d);
void print_vector(co nst vector<string>& s);

const string filename = "mydata";

int main(void)
{
DataInstances data;

data = getRecords(file name);
print_data(data );

return 0;
}

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

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

void print_data(cons t 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(*p os);
}
}

Following is the compile errors:

In function 'void print_data(cons t DataInstances&) ':
test.cpp:86: error: no match for 'operator=' in 'pos = (+
d)->std::list<_T p, _Alloc>::begin [with _Tp =
std::vector<std ::basic_string< char, std::char_trait s<char>,
std::allocator< char> >, std::allocator< std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char> > > >, _Alloc =
std::allocator< std::vector<std ::basic_string< char,
std::char_trait s<char>, std::allocator< char> >,
std::allocator< std::basic_stri ng<char, std::char_trait s<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_iter ator<std::vecto r<std::basic_st ring<char,
std::char_trait s<char>, std::allocator< char> >,
std::allocator< std::basic_stri ng<char, std::char_trait s<char>,
std::allocator< char> > > > >&
std::_List_iter ator<std::vecto r<std::basic_st ring<char,
std::char_trait s<char>, std::allocator< char> >,
std::allocator< std::basic_stri ng<char, std::char_trait s<char>,
std::allocator< char> > > > >::operator=(co nst
std::_List_iter ator<std::vecto r<std::basic_st ring<char,
std::char_trait s<char>, std::allocator< char> >,
std::allocator< std::basic_stri ng<char, std::char_trait s<char>,
std::allocator< char> > > > >&)
Any one give me some help ?
Thanks!

May 29 '06 #1
2 2619
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(cons t 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(*p os);
}
}

[snip]
Best

Kai-Uwe Bux
May 29 '06 #2
OK, now it works!
Thank you very much!

May 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7342
by: Mr. K.V.B.L. | last post by:
I want to start a map with keys but an empty vector<string>. Not sure what the syntax is here. Something like: map<string, vector<string MapVector; MapVector.insert(make_pair("string1", new vector<string>)); MapVector.insert(make_pair("string2", new vector<string>)); MapVector.insert(make_pair("string3", new vector<string>));
42
4472
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector of string, in one line. I could
0
7387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7798
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7738
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5956
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
688
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.