Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Parsing Integers

Why don't you have to parse in C++ to get input?

How come in C++ you can enter in integers with the cin command without parsing it from a string into an integer first? Can you not just let the user enter an integer without converting from string to integer?

1 Answer

Logan R
Logan R
22,989 Points

In Java, the Scanner returns the input as a String. That's just how it works.

With C++, you pass it what you want to take in, so for example:

int i;
cout << "Please enter an integer value: ";
cin >> i;

C++ knows the following will be an integer, so the input is expected and returned as an integer. The Java Scanner has no idea what the variable that it's taking in will be.