473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

bogus entries in map (std library)

Hi,

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,intentry>* fulldata ;

using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.

The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.

But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.

How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.

I am using debian etch with g++ version 4:4.1.1-15.

Thanks for any suggestions,

suresh

Dec 12 '07 #1
4 1405
suresh wrote:
I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,intentry>* fulldata ;

using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.

The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.

But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.

How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.
How do you know that there are "bogus entries"? Did you know that
using indexing on a map inserts a default-initialized value into
the map with the key you use do index?

map<int, doublewhoa;
if (whoa[42] == 0) {
std::cerr << "BOGUS!!!";
}

Is that what you're doing?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 12 '07 #2
suresh wrote:
Hi,

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,intentry>* fulldata ;
Syntactically invalid statement...
>
using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.

The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.

But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.

How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.

I am using debian etch with g++ version 4:4.1.1-15.

Thanks for any suggestions,

suresh
How can we help you if you don't post any code? (Although Victor's
guess is probably a good one given the uselessly little information
you've provided.)
Dec 12 '07 #3
Hi Victor

Thanks for the reply. I read Stroustrup carefully and wrote a small
piece of code to confirm the indexing behaviour. Thanks.

Mark, sorry for the cut paste error in my code. Actually it was
written like this:

typedef map<string,intentry;
vector<entry>* fulldata ;

Anyway I learned maps better now. Thank you both,

regards
suresh

On Dec 13, 1:56 am, Mark P <use...@fall2005REMOVE.fastmailCAPS.fm>
wrote:
suresh wrote:
Hi,
I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:
I have defined an array of vectors, where each vector element is a
map, like this:
vector<map<string,intentry>* fulldata ;

Syntactically invalid statement...


using new operator, fulldata is memory allocated and each vector's
size is made 10 by calling resize() function.
The maps are always updated using ++fulldata[i][j][key_string]; This
means that no key_string in the map can have corresponding zero
integer values.
But I get bogus entries in some maps with 0 values corresponding to
some valid key_string.
How can this happen? Interestingly this problem is noticed in the maps
stored in the 2nd position in the vector (for many vectors it is
seen). ie fulldata[i][2][key_string] is zero for many i values.
I am using debian etch with g++ version 4:4.1.1-15.
Thanks for any suggestions,
suresh

How can we help you if you don't post any code? (Although Victor's
guess is probably a good one given the uselessly little information
you've provided.)

Dec 13 '07 #4
In message
<01**********************************@e25g2000prg. googlegroups.com>,
suresh <su***************@gmail.comwrites
>Hi,

I am getting zero as value for some keys in my map which can never
happen as per my understanding of my code. These are the details:

I have defined an array of vectors, where each vector element is a
map, like this:

vector<map<string,intentry>* fulldata ;

using new operator
Why not just use a vector of vectors?
--
Richard Herring
Dec 13 '07 #5

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

Similar topics

10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
7
by: zbyszek | last post by:
I am working with a large C++ program which, for reasons of backward compatibility, uses C's printf and fprintf rather than iostreams. For a certain type of build I want to provide new functions...
5
by: cppaddict | last post by:
Hi, I have some code which uses std::map to associate cartesian POINTs with values. My current syntax for adding new (POINT,value) entries to the map is clunky -- it takes three lines for each...
12
by: Christoff Pale | last post by:
Hi, suppose I have a list of strings; I have to iterate of the strings and delete certain entries. I and not sure how to do this? for example: #include<list> #include<string>...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
12
by: levent | last post by:
What is an elegant way (using std::stream's) to extract number of white-space separated entries in a given line of a formatted text file? e.g.: Take this section of a file, 1 2.78 4 5 -0.003...
1
by: Maxwell | last post by:
Hello, I having having oodles of trouble using the std lib in my MC++ (VS.NET 2003) Class library. I figured out a simple sample to reproduce the errors I am having. Create a MC++ (VS.NET 2003)...
2
by: Mirandole | last post by:
Salut. Gros problème en C avec les tableaux à plusieurs entrée : #include <math.h> #include <stdio.h> #define maxt 12 #define maxh 50 Void main(int narg, char ** argv) { char tabl; //...
2
by: Neha | last post by:
#include <rw/tpslist.h> #include <iostream> using namespace std; int main(){ RWTPtrSlist<int> dates; dates.insert(new int(2)); // 6/2/52 dates.insert(new int(2)); // 6/2/52 //...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.