| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Funny Problem |
> a ship which is chars at the start and a train which is all
> digits......anyway i had this problem it seems with getc, ungetc
> and cin and cout ??? Aren't they compatible!!!
No.
Don't mix C stdio with C++ iostreams on the same file handles. They both
buffer the streams independantly. In fact, I'd recommend avoiding mixing
use of both in the same program if possible - there's probably very little
danger that it would cause any problem, but you're pulling in a lot of
redundant library code.
> Here is a bit of code
> while ( c=getc(stdin)!=EOF ) {
> if ( isdigit(c) ) {
> ungetc(c, stdin);
> end=1; // end=1 means end of ships is true!!
> }
> if ( !end ) {
> ungetc(c, stdin);
> cin >> tempship; // overloaded cin in ship class
> cout << "The details of the ship are "
<< tempship;
> // cout overloaded in ship class as well
> .....
while ( (c=cin.get()) !=EOF ) {
if ( isdigit(c) ) {
cin.putback(c);
end=1; // end=1 means end of ships is true!!
}
if ( !end ) {
cin.putback(c);
cin >> tempship; // overloaded cin in ship class
cout << "The details of the ship are "
<< tempship;
// cout overloaded in ship class as well
.....
david
---
* Origin: Unique Computing Pty Ltd (3:632/348)SEEN-BY: 50/99 54/54 620/243 623/625 630 632/103 301 348 365 386 998 633/371 SEEN-BY: 634/384 635/210 502 503 541 544 636/100 670/206 711/409 430 807 808 SEEN-BY: 711/809 932 934 712/623 713/888 714/906 800/1 @PATH: 632/348 635/503 50/99 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.