| | |
c++ Problem (Need help)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 148
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."
•
•
•
•
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 array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






