Getting lower-bound and upper-bound of strings input

R

Rhiner Dan

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.
 
M

Mike Wahler

Rhiner Dan said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,836
Latest member
BuyBlissBitesCBD

Latest Threads

Top