|
-
Jan 6th, 2002, 08:48 PM
#1
Thread Starter
New Member
cin.getline ahhh!!!!!!!
ok i'm tryin to learn c++ and i'm using microsoft visual c++ (xmas present from my uncle) ok here's my problem, i have this function
Code:
void pause()
{
char mybuffer [100];
cout << "Press Any key to continue";
cin.getline (mybuffer,100);
}
but everytime i call it it just flies right over the cin.getline unless i call it before the last like 5 lines of main
Code:
int main()
{
char choicetmp[5];
int choice;
// char tempvar [256];
cout << "1.) Add 2 Numbers" << endl;
cout << "2.) Subtract 2 Numbers" << endl;
cout << "3.) Divide 2 Numbers" << endl;
cout << "4.) Multiply 2 Numbers" << endl;
cout << endl;
cout << "Enter the number you want: ";
cin.getline(choicetmp,5);
choice = atoi(choicetmp);
switch(choice)
{
case 1: add();
}
pause();
return 0;
}
i have no idea what it is but it's driving me nuts!! any help would be appreciated!
"Run Run Run as fast as you can.... you can't catch me... i'm the possessed mental case man"
-
Jan 6th, 2002, 08:55 PM
#2
Thread Starter
New Member
OH YEA GO ME!!@#!@%
GO FARKIN ME!@$!@%
figured it out myself... apparently cin >> and cin.getline do not cooperate so just used cin.getline and atoi to make the char int!
"Run Run Run as fast as you can.... you can't catch me... i'm the possessed mental case man"
-
Jan 6th, 2002, 09:34 PM
#3
Member
Ya usually sya something like
cin >> x;
for int's
and cin.getline
for strings
-
Jan 6th, 2002, 09:37 PM
#4
Thread Starter
New Member
yea but when you use cin >> with cin.getline it goes all screwy and cin.getline reads what was put to the cin >> so you just gotta use atoi to like convert it from chars to int... dunno i think i'm just like making it work tho
"Run Run Run as fast as you can.... you can't catch me... i'm the possessed mental case man"
-
Jan 6th, 2002, 09:59 PM
#5
Member
You don't want to use cin >> and getline on the same line hehe.
Here is a example:
#include <iostream.h>
int main()
{
int x;
cout << "Enter a number:";
cin >> x;
cout << endl;
cout << "The Number You Entered Was:" << x << endl;
return 0;
}
That's the simplest way to collect numbers..
-
Jan 6th, 2002, 10:09 PM
#6
Thread Starter
New Member
yea but what i was trying to do was add a pause thing
void pause()
{
char crap [1];
cout << "Press any key to continue"l
cin.getline (crap,1);
}
but THEN like 10 mins later i learn about about system("pause") and all so now i'm like yippie!!
"Run Run Run as fast as you can.... you can't catch me... i'm the possessed mental case man"
-
Jan 7th, 2002, 10:50 AM
#7
Addicted Member
If you want the program to halt, try putting in cin.get(); once or twice in your code and it will need a key-press to proceed......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|