size of a vector

hello guys. i've found something that i don't understand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream.h>
#include<conio>
#include<vector>
#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{

vector<int>v(10,5);
                 if (v.size()==10u)
                 cout <<"What the f... is u?";
getch();
        return 0;
}
//---------------------------------------------------------------------------
 


Can you please explain me what does that u(in 10u)mean? what is that?
it means the 10 should be interpretted as an unsigned instead of as an int.

Much like how the 'f' suffix indicates you want a float instead of a double.

Here is a test program you can try (your output may vary slightly):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <typeinfo>
#include <iostream>

using namespace std;

int main()
{
    cout << typeid(10).name() << endl;      // "int"
    cout << typeid(10u).name() << endl;     // "unsigned int"
    cout << typeid(1.0).name() << endl;     // "double"
    cout << typeid(1.0f).name() << endl;    // "float"

    cin.get();
}
very good @Disch and very good exmaple : typeid :D
Thank you very much, Disch
Help me a lot, thanks!
Well I'm glad so many different people found it helpful!

haha
Topic archived. No new replies allowed.