473,473 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

list<string> insertion fails

Compilation fails at "line.insert(line.end(), x.begin(), i);" and I
can't figure out why. Here is the code:

/*
5-1. Design and implement a program to produce a permuted index. A
permuted
index is one in which each phrase is indexed by every word in the
phrase.
*/

#include <cctype>
#include <iostream>
#include <string>
#include <list>

using std::cin;
using std::cout;
using std::isspace;
using std::string;
using std::list;

int main() {
string x;
list<list<string indexes;
while (getline(cin, x)) {
string::const_iterator i = x.begin();
list<stringline;
while (i < x.end()) {
while (i < x.end() && isspace(*i)) x.erase(*(i++));
while (i < x.end() && !isspace(*i)) ++i;
line.insert(line.end(), x.begin(), i);
}
indexes.push_back(line);
}
for (list<list<string::const_iterator i = indexes.begin();
i != indexes.end(); ++i) {
for (list<string>::const_iterator j = i->begin(); j != i->end(); +
+j)
cout << *j << std::endl;
}
return 0;
}

... and here is the compilation error:
g++ 5-1.cpp -o 5-1 -Wall
5-1.cpp: In function ‘int main()’:
5-1.cpp:26: error: no matching function for call to
‘std::list<std::basic_string<char, std::char_traits<char>,
std::allocator<char, std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char >
>::insert(std::_List_iterator<std::basic_string<ch ar,
std::char_traits<char>, std::allocator<char >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
__gnu_cxx::__normal_iterator<const char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char >&)’
/usr/include/c++/4.2/bits/list.tcc:86: note: candidates are: typename
std::list<_Tp, _Alloc>::iterator std::list<_Tp,
_Alloc>::insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp =
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, _Alloc = std::allocator<std::basic_string<char,
std::char_traits<char>, std::allocator<char >]
/usr/include/c++/4.2/bits/stl_list.h:808: note: void
std::list<_Tp, _Alloc>::insert(std::_List_iterator<_Tp>, size_t, const
_Tp&) [with _Tp = std::basic_string<char, std::char_traits<char>,
std::allocator<char, _Alloc =
std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char >]
make: *** [5-1] Error 1
Jul 29 '08 #1
3 3418
banangroda wrote:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I
can't figure out why. Here is the code:

/*
5-1. Design and implement a program to produce a permuted index. A
permuted
index is one in which each phrase is indexed by every word in the
phrase.
*/

#include <cctype>
#include <iostream>
#include <string>
#include <list>

using std::cin;
using std::cout;
using std::isspace;
using std::string;
using std::list;

int main() {
string x;
list<list<string indexes;
while (getline(cin, x)) {
string::const_iterator i = x.begin();
list<stringline;
while (i < x.end()) {
while (i < x.end() && isspace(*i)) x.erase(*(i++));
while (i < x.end() && !isspace(*i)) ++i;
line.insert(line.end(), x.begin(), i);
}
indexes.push_back(line);
}
for (list<list<string::const_iterator i = indexes.begin();
i != indexes.end(); ++i) {
for (list<string>::const_iterator j = i->begin(); j != i->end(); +
+j)
cout << *j << std::endl;
}
return 0;
}
[..]
Your 'line' is a list of strings. Your 'x.begin()' is an iterator in a
string. If you intended to insert the entire 'x' string into your list
of strings (append), then you probably wanted to do

line.insert(line.end(), x);

If not, describe to us *what it is you're trying to accomplish*.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 29 '08 #2
On Jul 29, 8:17*pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
banangroda wrote:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I
can't figure out why. Here is the code:
/*
* *5-1. Design and implement a program to produce a permuted index.A
permuted
* *index is one in which each phrase is indexed by every word in the
phrase.
*/
#include <cctype>
#include <iostream>
#include <string>
#include <list>
using std::cin;
using std::cout;
using std::isspace;
using std::string;
using std::list;
int main() {
* *string x;
* *list<list<string indexes;
* *while (getline(cin, x)) {
* * * * * *string::const_iterator i = x.begin();
* * * * * *list<stringline;
* * * * * *while (i < x.end()) {
* * * * * * * * * *while (i < x.end() && isspace(*i)) x.erase(*(i++));
* * * * * * * * * *while (i < x.end() && !isspace(*i)) ++i;
* * * * * * * * * *line.insert(line.end(), x.begin(), i);
* * * * * *}
* * * * * *indexes.push_back(line);
* *}
* *for (list<list<string::const_iterator i = indexes.begin();
* *i != indexes.end(); ++i) {
* * * * * *for (list<string>::const_iterator j = i->begin(); j != i->end(); +
+j)
* * * * * * * * * *cout << *j << std::endl;
* *}
* *return 0;
}
[..]

Your 'line' is a list of strings. *Your 'x.begin()' is an iterator in a
string. *If you intended to insert the entire 'x' string into your list
of strings (append), then you probably wanted to do

* * line.insert(line.end(), x);

If not, describe to us *what it is you're trying to accomplish*.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I want to insert the contents of 'x' from its start through 'i' into
'line'.
Jul 29 '08 #3
banangroda wrote:
[..]
I want to insert the contents of 'x' from its start through 'i' into
'line'.
See 'substr' member of 'string'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 29 '08 #4

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

Similar topics

2
by: gbgbgbgb | last post by:
Hi, I have a definition bool operator<(string s_s, string s_t) { .... } and a variable list<string> concomp;
2
by: s | last post by:
I'm getting compile errors on the following code: <code> #include <iostream> #include <fstream> #include <list> #include <string> using namespace std;
3
by: aquanutz | last post by:
Ok, I have a list of strings (list<string> stringList) that I want to sort alphabetcially, only "sort(stringList.begin(), stringList.end()); ) does not work. Any insight would be helpful. Thanks!
3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
4
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
4
by: rsa_net_newbie | last post by:
Hi there, I have a Managed C++ object (in a DLL) which has a method that is defined like ... Generic::List<String^>^ buildList(String^ inParm) Now, when I compile it, I get "warning C4172:...
2
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
4
by: parez | last post by:
Hi, I am trying to serialize List<List<string>. With the following code public List<List<string>DataRows { get; set; }
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.