Some questions I am facing to

Hi guys I got some questions I need help.

1. What is the difference between auto and decltype?

2. The parenthesis makes me confused.
getline(cin, mystr)
cin.getline()
string mystring("1024")
stringstream(mystr) >> myint

I am reading basic input/output tutorial and these they don't give me something like formala or definition of the four functions unlike they have done so far.
So, what I'm asking for is what does that in parenthesis mean and what should be in the parenthesis?
For getline(cin, mystr), I guess it works as it transfers the value of a variable on the right_hand of comma to the variable on the left_hand of the comma.
For cin.getline(), it seems to be basically same with cin>> but it takes string, not one character.
for string mystring("1024"), All I understood is that 'mystring' is the declared variable, and the value in (" ") is stored in the variable, it says it is string but can handle numbers, as I understand, but I get no difference.
for the last one, it looks like it puts something in the variable myint, is it from stringstream? or mystr..

Please help me out !
What is the difference between auto and decltype?
It is subtle but important. In fact Scott Meyers had devoted whole chapter for type deduction in Modern C++ (10% 0f whole book). In short auto works almost like template argument deduction and deduces type of object from initializer; and decltype returns fully decorated object type (preserving referenceness) and can be used anywhere where type name is expected (even where auto will not work).

Lines 1 and 2: here parentheses are denoting function call. Syntax is following: function-name( arguments ).
Line 3: there parentheses are denoting direct initialization (you can thing of it as constructor call). And "1024" is a string literal, not a number.
In last one it is direct initialization too. We are creating unnamed temporary object and calling operator>> on it. It is equivalent of
1
2
stringstream temp(mystr);
temp >> myint;
Thank you so much !

it really helps me !!
Topic archived. No new replies allowed.