By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,193 Members | 843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,193 IT Pros & Developers. It's quick & easy.

Getting lower-bound and upper-bound of strings input

P: n/a
Here are the errors from my Dev-c compiler

////////////////////////////////////////////////////////////////////////////
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c Tests.cpp -o Tests.o
-I"C:/Dev-Cpp/include/c++/3.3.1"
-I"C:/Dev-Cpp/include/c++/3.3.1/mingw32"
-I"C:/Dev-Cpp/include/c++/3.3.1/backward"
-I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"
-I"C:/Dev-Cpp/include"
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h: In constructor
`std::pair<_T1,
_T2>::pair(const std::pair<_U1, _U2>&) [with _U1 =
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,

std::allocator<std::string> > >, _U2 =
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >, _T1 = std::string*, _T2 =
std::string*]':
Tests.cpp:59: instantiated from here
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h:88: error: cannot convert
`const
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >' to `std::string*' in
initialization
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h:88: error: cannot convert
`const
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >' to `std::string*' in
initialization
make.exe: *** [Tests.o] Error 1
Execution terminated
//////////////////////////////////////////////////////////////////////////////

And here is the code that emits those errors
// input strings and save them into vector of strings called str.
// begin to fetch from here.
while(std::getline(std::cin,hold)){
std::pair<std::string*, std::string*>
result=std::equal_range(str.begin(),str.end(), hold);
std::cout<<"the fresult is: "<<*result.first<<'\n';
std::cout<<"the lresult is: "<<*result.second<<'\n';
}

Using string pointers in pair<> like those above are not allowed right
?
I tested input string source code and compiler said it was correctly
witten but the above code gave errors..I am new to stl, Please
help..Thank you in advance.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Rhiner Dan" <st****@centralpets.com> wrote in message
news:f5**************************@posting.google.c om...
Here are the errors from my Dev-c compiler

////////////////////////////////////////////////////////////////////////////
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c Tests.cpp -o Tests.o
-I"C:/Dev-Cpp/include/c++/3.3.1"
-I"C:/Dev-Cpp/include/c++/3.3.1/mingw32"
-I"C:/Dev-Cpp/include/c++/3.3.1/backward"
-I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"
-I"C:/Dev-Cpp/include"
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h: In constructor
`std::pair<_T1,
_T2>::pair(const std::pair<_U1, _U2>&) [with _U1 =
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,

std::allocator<std::string> > >, _U2 =
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >, _T1 = std::string*, _T2 =
std::string*]':
Tests.cpp:59: instantiated from here
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h:88: error: cannot convert
`const
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >' to `std::string*' in
initialization
C:/Dev-Cpp/include/c++/3.3.1/bits/stl_pair.h:88: error: cannot convert
`const
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocator<std::string> > >' to `std::string*' in
initialization
make.exe: *** [Tests.o] Error 1
Execution terminated
//////////////////////////////////////////////////////////////////////////////

And here is the code that emits those errors
// input strings and save them into vector of strings called str.
// begin to fetch from here.
while(std::getline(std::cin,hold)){
std::pair<std::string*, std::string*>
result=std::equal_range(str.begin(),str.end(), hold);
std::cout<<"the fresult is: "<<*result.first<<'\n';
std::cout<<"the lresult is: "<<*result.second<<'\n';
}

Using string pointers in pair<> like those above are not allowed right
?
I tested input string source code and compiler said it was correctly
witten but the above code gave errors..I am new to stl, Please
help..Thank you in advance.


#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

int main()
{
std::vector<std::string> str;
std::string hold;

while(std::getline(std::cin, hold))
{
std::pair<std::vector<std::string>::iterator,
std::vector<std::string>::iterator>
result(std::equal_range(str.begin(),
str.end(),
hold));

std::cout << "the fresult is: " << *result.first << '\n';
std::cout << "the lresult is: " << *result.second << '\n';
}

return 0;
}

-Mike
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.