#include<iostream>
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","123"),
pair<const char*,const char*>("1234","1234"),
pair<const char*,const char*>("12345","12345"),
};
cout<<sizeof(char)<<endl;
cout<<sizeof(arr[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(arr)/sizeof(arr[0])<<endl;
return 0;
}
gives me :
1
8 <- ????? Why ????
40
5 4 12226
onkar wrote:
#include<iostream>
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","123"),
pair<const char*,const char*>("1234","1234"),
pair<const char*,const char*>("12345","12345"),
};
cout<<sizeof(char)<<endl;
cout<<sizeof(arr[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(arr)/sizeof(arr[0])<<endl;
return 0;
}
gives me :
1
8 <- ????? Why ????
2*sizeof(char*) ?
--
Ian Collins.
onkar wrote:
#include<iostream>
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","123"),
pair<const char*,const char*>("1234","1234"),
pair<const char*,const char*>("12345","12345"),
Have a look at std::make_pair.
};
cout<<sizeof(char)<<endl;
cout<<sizeof(arr[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(arr)/sizeof(arr[0])<<endl;
return 0;
}
gives me :
1
8 <- ????? Why ????
Why not? What did you expect?
40
5
Hi,
sizeof of STL containers does not return the size of the contained
object - sizeof vector<charcontaing 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<iostream>
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","123"),
pair<const char*,const char*>("1234","1234"),
pair<const char*,const char*>("12345","12345"),
};
cout<<sizeof(char)<<endl;
cout<<sizeof(arr[0])<<endl;
cout<<sizeof arr<<endl;
cout<<sizeof(arr)/sizeof(arr[0])<<endl;
return 0;
}
gives me :
1
8 <- ????? Why ????
40
5
In message <11*********************@b28g2000cwb.googlegroups. com>, so***********@gmail.com writes
[Please don't top-post. Rearranged]
>onkar wrote:
>#include<iostream> 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","123"), pair<const char*,const char*>("1234","1234"), pair<const char*,const char*>("12345","12345"), }; cout<<sizeof(char)<<endl; cout<<sizeof(arr[0])<<endl; cout<<sizeof arr<<endl; cout<<sizeof(arr)/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<charcontaing 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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:
...
|
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
|
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....
|
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...
|
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
{
|
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...
|
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 ...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |