find the string in the std::list
-
Hi, I am storing all the barcode into below declared list
typedef std::list<char* > SERIAL_NUM_BARCODE_LIST; SERIAL_NUM_BARCODE_LIST SerialNumDescList;
Now before adding to list I have to check whether barcode exist in the list or not. If barcode does not exist than only I have to add it.typedef std::list<char* >::iterator BARCODE_LIST_ITER; BARCODE_LIST_ITER BarcodeListIter; for(BarcodeListIter = SerialNumBarcodeList.begin(); BarcodeListIter != SerialNumBarcodeList.end();BarcodeListIter++) strcmp(SerialNumBarcodeList.front(),Barcode)
Is there simple find method present in STL to check inside the list. Thanks:-D -
Hi, I am storing all the barcode into below declared list
typedef std::list<char* > SERIAL_NUM_BARCODE_LIST; SERIAL_NUM_BARCODE_LIST SerialNumDescList;
Now before adding to list I have to check whether barcode exist in the list or not. If barcode does not exist than only I have to add it.typedef std::list<char* >::iterator BARCODE_LIST_ITER; BARCODE_LIST_ITER BarcodeListIter; for(BarcodeListIter = SerialNumBarcodeList.begin(); BarcodeListIter != SerialNumBarcodeList.end();BarcodeListIter++) strcmp(SerialNumBarcodeList.front(),Barcode)
Is there simple find method present in STL to check inside the list. Thanks:-DYou can simply compare the contents of the iterator (so, the string) with the name of the new barcode. To access the string through the iterator, just use this:
(*BarcodeListIter)
-
Hi, I am storing all the barcode into below declared list
typedef std::list<char* > SERIAL_NUM_BARCODE_LIST; SERIAL_NUM_BARCODE_LIST SerialNumDescList;
Now before adding to list I have to check whether barcode exist in the list or not. If barcode does not exist than only I have to add it.typedef std::list<char* >::iterator BARCODE_LIST_ITER; BARCODE_LIST_ITER BarcodeListIter; for(BarcodeListIter = SerialNumBarcodeList.begin(); BarcodeListIter != SerialNumBarcodeList.end();BarcodeListIter++) strcmp(SerialNumBarcodeList.front(),Barcode)
Is there simple find method present in STL to check inside the list. Thanks:-DIdeally, you should store the barcodes as strings instead of a pointer. For example:
std::liststd::string SerialNumBarcodeList;
...
std::list<string>::const_iterator it = std::find(SerialNumBarcodeList.begin(), SerialNumBarcodeList.end(), BarCode);
if (it != SerialNumBarcodeList.end())
{
// Found!
...
}-- modified at 2:56 Monday 27th March, 2006
-
Ideally, you should store the barcodes as strings instead of a pointer. For example:
std::liststd::string SerialNumBarcodeList;
...
std::list<string>::const_iterator it = std::find(SerialNumBarcodeList.begin(), SerialNumBarcodeList.end(), BarCode);
if (it != SerialNumBarcodeList.end())
{
// Found!
...
}-- modified at 2:56 Monday 27th March, 2006