| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
basic string
i try to run this program but the cin.get() not executing .
i don't know why here is a part of my code : #include <iostream> #include <stdlib.h> #include <string.h> #include <cctype> #include <cstring> using namespace std; const int size = 100; int isdigit (int ch); bool isdigit (char p); bool isdigit1 (const char p[], const int size); int main() { char dig; char str[size]; char k ; cout << "this program will test if your input is digit or not"<<endl; cout << "please add your input :"; cin >> dig; if (isdigit (dig)) { cout << "\nyour input is a digit."<<endl; } else { cout<< "\nnot a digit."<<endl; } cout << "\nEnter a String :"; cin.get(str , size); do { cin.get(k); }while (k !='\n'); system("PAUSE"); return 0; } //----------------------------------------------------------------------------------------- bool isdigit (char p) { int m = 0; m = p ; if ( isdigit (m) !=0) return true; else return false; } |
|
#2
|
|||
|
|||
|
Its a bug with MS IDE you have to make a call to cin.get(); before you call cin.get( str, size ); this grabs the newline char that is still kicking around in the input buffer from your call to cin >> dig;, you dig? Microsoft hired a company called Dinkumware to write their version of the STL for them.
http://www.dinkumware.com/ Unfortunetly it has its share of bugs. |
|
#3
|
|||
|
|||
|
how
and how can i cin.get(); before you call cin.get( str, size )
i don't know STL yet. i'm working with very basics strings. thanks |
|
#4
|
|||
|
|||
|
Instead of writing:
cout << "\nEnter a String :"; cin.get(str , size); write: cout << "\nEnter a String :"; cin.get(); cin.get(str , size); However if you didn't make the preivous call cin >> dig; or you placed that call after you enter the string it is not neccessary to call cin.get() before cin.get( str, size ). Is there some reason why you have to use cin.get() cause you could just use the >> operator. cin >> str; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > basic string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|