absolute beginner query - check code

going through a tutorial and it says to try writing code for:

(c) a program which reads in two integers on one line and displays them in reverse order. If the input was 3 99, the output should be 99 3.

The answer is:

c) #include <iostream>
using namespace std;
int main()
{ cout << "Please key in two numbers separated by a space: ";
int x, y;
cin >> x >> y;
cout << y << " " << x << endl;

question is regarding " " on bottom. Elsewhere it says to use "" for words. To add a space between the 2 numbers, is the space classed as words?
Space is a character, ya.
Single quotes are used for single characters, e.g.:

cout << 'a' << ' ' << '\t' << '\x90' << '\n';

Double quotes are used for string literals (aka character arrays), e.g.:

cout << "Hello, World!\n";

In you case you could (and in my opinion, should) use ' ' instead.
Last edited on
Topic archived. No new replies allowed.