| | |
c++ Problem (Need help)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 151
Reputation:
Solved Threads: 3
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
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 If you ask me questions through Private messaging I won't reply.
>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).
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.
>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).
C++ Syntax (Toggle Plain Text)
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.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
•
•
What I am trying to do is change the
cin >> varible;
into something different so when I find it easier when I code.
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the C++ Forum
- Previous Thread: need help with DarkGDK
- Next Thread: Crazy Unexplained Error (using DarkGDK)
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






