Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Getting lower-bound and upper-bound of strings input

Reply
Thread Tools

Getting lower-bound and upper-bound of strings input

 
 
Rhiner Dan
Guest
Posts: n/a
 
      03-26-2005
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:air<_T1,
_T2>:air(const std:air<_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:air<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.
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      03-27-2005

"Rhiner Dan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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:air<_T1,
> _T2>:air(const std:air<_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:air<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:air<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


 
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
Entering strings as user input but interpreting as Python input (sortof) Chris Carlen Python 1 09-18-2007 01:58 AM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Getting User Input after getting Input from a file dei3cmix@uga.edu C++ 3 03-23-2006 05:01 AM
Catching std::strings and c-style strings at once Kurt Krueckeberg C++ 2 11-17-2004 03:53 AM
input fields and strings Tim Fooy HTML 2 09-14-2004 06:37 AM



Advertisments