What I am trying to do is change the

cin >> varible;

into something different so when I find it easier when I code.

The line that I am changing it to is

input (varible);

i am using this:

#define input(i) cin >> (i);

it works, however it will only allow me to input one thing and not loads for example:

say ("Welcome to my first script, what is your name");
input(name);
-- will work

but, this will not:

say ("Welcome to my first script, what is your name");
input(name);
say ("That's great! How old are you?")
input(age);

any ideas, please help :( thank you

Recommended Answers

All 5 Replies

getline(cin, variable);

Generally the more preferable option in the majority of cases as far as I'm aware. (It'll get an entire line including whitespace, use enter to terminate input)

getline as Yiuca said.

Never use macros like that. template <typename T> void input_cin(T variable);

template <typename T> void input_cin(T variable);

doesn't work :(

>template <typename T> void input_cin(T variable);
>doesn't work
Well... you need to actually write the function, too. That's just the prototype (and you probably want it to return something, so don't use void).

template <typename T> T input_cin(T variable)
{
  std::cin >> variable;
  return input;
}

However, I recommend using getline() instead of cin for obvious reasons. It effectively removes nearly all issues associated with clearing the input buffer, as described here, and will fix your original problem regarding cin only grabbing a single word from the input buffer.

What I am trying to do is change the

cin >> varible;

into something different so when I find it easier when I code.

Why do this? Is cin hard to remember? You need to get used it, you'll see it everywhere!! Think of it as "console input", this might help you remember. When I started C++ I was forgetting everything but as I learned I remember them, so do not worry :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.