C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 15th, 2004, 01:31 PM
maro009 maro009 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 maro009 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;
}

Reply With Quote
  #2  
Old December 15th, 2004, 02:18 PM
marmo marmo is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 37 marmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 20 sec
Reputation Power: 5
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.

Reply With Quote
  #3  
Old December 15th, 2004, 03:48 PM
maro009 maro009 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 6 maro009 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old December 15th, 2004, 07:37 PM
marmo marmo is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 37 marmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 20 sec
Reputation Power: 5
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;

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > basic string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT