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

Home Posts Topics Members FAQ

Issue with std::lower_bound

hi there,

I do not understand why the following piece of code is not working
for me. I have a set of cstrings, where I am trying to find one 'UT'.
If I search from "AE" to "OB or OW" everything is fine, but when
searching from "AE" to "US or SS"... then the code stops working...

Anyone can shed some light on it ?

thanks a bunch !
-Mathieu

#include <sstream>
#include <iostream>

static const char *VRStringsTest[] = {
"??", // 0
"AE", // 1
"AS", // 2
"AT", // 3
"CS", // 4
"DA", // 5
"DS", // 6
"DT", // 7
"FD", // 8
"FL", // 9
"IS", // 10
"LO", // 11
"LT", // 12
"OB", // 13
"OF", // 14
"OW", // 15
"PN", // 16
"SH", // 17
"SL", // 18
"SQ", // 19
"SS", // 20
"ST", // 21
"TM", // 22
"UI", // 23
"UL", // 24
"UN", // 25
"US", // 26
"UT", // 27
"OB or OW", // 28
"US or SS", // 29
"US or SS or OW", //30
0
};
class MySort
{
public:
bool operator() (const char *a, const char *b)
{
if( a[0] == b[0] )
return a[1] < b[1];
return a[0] < b[0];
}
};

int main(int, char *[])
{
const char vr[] = "UT";
static const int N = 28; // only consider a subset
static const char **start = VRStringsTest+1; // let's start at
element #1
//static const char **end = VRStringsTest+N; // working !
static const char **end = VRStringsTest+N+1; // not working
const char **p =
std::lower_bound(start, end, vr, MySort());
if( (*p)[0] != vr[0] || (*p)[1] != vr[1] )
{
std::cerr << "INVALID" << std::endl;
}
else
{
std::cerr << *p << std::endl; // Yes, we found 'UT' !
}

return 0;
}
Nov 19 '07 #1
0 1507

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

Similar topics

4
by: Alex Vinokur | last post by:
============================= Windows 2000 MinGW 2.0.0.-2 GNU gcc/g++ version 3.2 ============================= I have some question concerning the lower_bound algorithm. ========= C++ code...
44
by: jmoy | last post by:
I am a C programmer graduating to C++. As an exercise I wrote a program to count the number of times that different words occur in a text file. Though a hash table might have been a better choice,...
3
by: Allerdyce.John | last post by:
On page 181 of Effective STL, it said 'It 's knowning when equal_range is a better way to search than lower_bound, knowing when lower bound is preferable to find..." My question is understand...
3
by: Diego Martins | last post by:
Andrew Koenig wrote:
3
by: could.net | last post by:
I have a class board, like this: struct board { int x1, x2, h; int time1, time2; void calculate_time(); void assign(int x1__,int x2__,int h__); }; And I have n boards stored in an array...
8
by: brekehan | last post by:
If I have a class MyClass { ...bunch o data and methods int x; }; and a stl container of MyClass objects Is there a way to use std::find to get all the elements whose member x
1
by: phdscholar80 | last post by:
I am using the following code: #include <vector> #include <algorithm> class A { }; bool comparator( A * b, const char * a )
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
4
by: RiderOfGiraffes | last post by:
Hi, I'm trying to compile (someone else's) code on SuSE 11.0. It worked fine on SuSE 10.3, but now it's telling me that lower_bound is not a member of std. I'm assuming something has changed...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.