Getting lower-bound and upper-bound of strings input

Discussion in 'C++' started by Rhiner Dan, Mar 26, 2005.

  1. Rhiner Dan

    Rhiner Dan Guest

    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.
    Rhiner Dan, Mar 26, 2005
    #1
    1. Advertising

  2. Rhiner Dan

    Mike Wahler Guest

    "Rhiner Dan" <> wrote in message
    news:...
    > 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
    Mike Wahler, Mar 27, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    707
    J├╝rgen Exner
    Dec 7, 2004
  2. sunil panda

    Lower bound & Upper bound

    sunil panda, Dec 25, 2003, in forum: Java
    Replies:
    9
    Views:
    7,236
    thushara wijeratna
    Oct 7, 2008
  3. ANM
    Replies:
    2
    Views:
    1,358
    Thomas Schodt
    Mar 7, 2004
  4. Pierre

    Manipulation of strings: upper/lower case

    Pierre, Jan 15, 2005, in forum: C Programming
    Replies:
    32
    Views:
    911
    Lawrence Kirby
    Jan 20, 2005
  5. BlackHelicopter
    Replies:
    0
    Views:
    512
    BlackHelicopter
    Jan 31, 2013
Loading...

Share This Page