473,799 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pair STL query

#include<iostre am>
using namespace std;
int main(void){
const pair<const char*,const char*arr[]={
pair<const char*,const char*>("1","1") ,
pair<const char*,const char*>("12","12 "),
pair<const char*,const char*>("123","1 23"),
pair<const char*,const char*>("1234"," 1234"),
pair<const char*,const char*>("12345", "12345"),
};
cout<<sizeof(ch ar)<<endl;
cout<<sizeof(ar r[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(ar r)/sizeof(arr[0])<<endl;
return 0;
}
gives me :

1
8 <- ????? Why ????
40
5

Jul 8 '06 #1
4 12255
onkar wrote:
#include<iostre am>
using namespace std;
int main(void){
const pair<const char*,const char*arr[]={
pair<const char*,const char*>("1","1") ,
pair<const char*,const char*>("12","12 "),
pair<const char*,const char*>("123","1 23"),
pair<const char*,const char*>("1234"," 1234"),
pair<const char*,const char*>("12345", "12345"),
};
cout<<sizeof(ch ar)<<endl;
cout<<sizeof(ar r[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(ar r)/sizeof(arr[0])<<endl;
return 0;
}
gives me :

1
8 <- ????? Why ????
2*sizeof(char*) ?

--
Ian Collins.
Jul 8 '06 #2
onkar wrote:
#include<iostre am>
using namespace std;
int main(void){
const pair<const char*,const char*arr[]={
pair<const char*,const char*>("1","1") ,
pair<const char*,const char*>("12","12 "),
pair<const char*,const char*>("123","1 23"),
pair<const char*,const char*>("1234"," 1234"),
pair<const char*,const char*>("12345", "12345"),
Have a look at std::make_pair.
};
cout<<sizeof(ch ar)<<endl;
cout<<sizeof(ar r[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(ar r)/sizeof(arr[0])<<endl;
return 0;
}
gives me :

1
8 <- ????? Why ????
Why not? What did you expect?
40
5
Jul 8 '06 #3
Hi,

sizeof of STL containers does not return the size of the contained
object - sizeof vector<charcont aing 100 chars is not 100. You need to
check your STL implementation of pair to see why it is returning 8.
Thanks and regards
Sonison James
onkar wrote:
#include<iostre am>
using namespace std;
int main(void){
const pair<const char*,const char*arr[]={
pair<const char*,const char*>("1","1") ,
pair<const char*,const char*>("12","12 "),
pair<const char*,const char*>("123","1 23"),
pair<const char*,const char*>("1234"," 1234"),
pair<const char*,const char*>("12345", "12345"),
};
cout<<sizeof(ch ar)<<endl;
cout<<sizeof(ar r[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(ar r)/sizeof(arr[0])<<endl;
return 0;
}
gives me :

1
8 <- ????? Why ????
40
5
Jul 10 '06 #4
In message <11************ *********@b28g2 000cwb.googlegr oups.com>,
so***********@g mail.com writes

[Please don't top-post. Rearranged]
>onkar wrote:
>#include<iostr eam>
using namespace std;
int main(void){
const pair<const char*,const char*arr[]={
pair<const char*,const char*>("1","1") ,
pair<const char*,const char*>("12","12 "),
pair<const char*,const char*>("123","1 23"),
pair<const char*,const char*>("1234"," 1234"),
pair<const char*,const char*>("12345", "12345"),
};
cout<<sizeof(ch ar)<<endl;
cout<<sizeof(ar r[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(ar r)/sizeof(arr[0])<<endl;
return 0;
}
gives me :

1
8 <- ????? Why ????
40
5


sizeof of STL containers does not return the size of the contained
object - sizeof vector<charcont aing 100 chars is not 100.
std::pair isn't a "container" the way vector is. It's just a templated
2-element structure.
>You need to
check your STL implementation of pair to see why it is returning 8.
What would you expect the size of the following to be?

struct {
const char * first;
const char * second;
};
--
Richard Herring
Jul 10 '06 #5

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

Similar topics

14
45872
by: Neil Zanella | last post by:
Hello, I would like to ask how come the design of C++ includes std::pair. First of all I don't think many programmers would use it. For starters, what the first and second members are depends on what you are using the pair for. For instance if I am using coordinates in two dimensional space then I like to use x and y. So I might as well define my own struct with x and y members in it and create a constructor so
3
14040
by: JustSomeGuy | last post by:
in the stl map class I see the use of a function pair and make_pair. What is the difference between pair and make_pair? dictionary.insert(std::pair<Key, Value>(k,v)); works as well as: dictionary.insert(std::make_pair<Key, Value>(k,v));
6
2755
by: pmatos | last post by:
Hi all, Is there a way of (after creating a pair) set its first and second element of not? (pair is definitely a read-only struct)? Cheers, Paulo Matos
1
1585
by: MDS | last post by:
All, I am endeavouring to implement an "Also in the area" feature to an Access 97 DB. Within the table, there are two columns drawn from the same domain - let's call them Place A and Place B. Place A and Place B form the composite primary key. When the user enters "Place A" is in the area of "Place B," it should
3
12682
by: Jon | last post by:
Hi, I have hyperlink objects in a datagrid that redirect the user back to the current page with this syntax: <a href="mypage.aspx?id=foo"> When the page reloads, code in Page_Load then takes the appropriate action based on finding the 'id' name/value pair in the URL querystring. This works well.
4
3452
by: Florent Garcin | last post by:
Hello! I would like to use the map structure with a key of Pair<string, string> and an int as the value. Pair is defined as: template <class T1, class T2> class Pair {
11
9121
by: kietzi | last post by:
Hello world, I was wondering whether it would be possible to create a map which uses a pair of ints as key and a float as value. I have used maps with const char* as key, but have so far not been successful to use a version which uses pairs as keys. For instance, I would like to set up the map as follows: struct eqstr { bool operator()(pair<int,int> s1, pair<int,int> s2) const{
1
1158
by: deepu1 | last post by:
i want to compare n pair of tables. i know to compare two tables the query is table 1 is having following columns uprn description blocknumber 1 gf 10 2 gf 20 and table2 is
10
3792
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3762
muto222
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.