Click here to Skip to main content
15,902,802 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralProblem when executing this code Pin
29-Sep-03 12:33
suss29-Sep-03 12:33 
GeneralRe: Problem when executing this code Pin
Paul Belikian29-Sep-03 13:03
Paul Belikian29-Sep-03 13:03 
GeneralRe: Problem when executing this code Pin
Tim Smith29-Sep-03 13:17
Tim Smith29-Sep-03 13:17 
GeneralRe: Problem when executing this code Pin
JT Anderson29-Sep-03 13:19
JT Anderson29-Sep-03 13:19 
GeneralHow bout this Pin
shawnsch29-Sep-03 13:38
shawnsch29-Sep-03 13:38 
GeneralRe: How bout this Pin
ZoogieZork29-Sep-03 14:35
ZoogieZork29-Sep-03 14:35 
GeneralRe: How bout this Pin
shawnsch29-Sep-03 17:41
shawnsch29-Sep-03 17:41 
GeneralRe: How bout this Pin
ZoogieZork29-Sep-03 18:50
ZoogieZork29-Sep-03 18:50 
I haven't read any of the C++ books by Herb Schildt, but I've heard both good and bad things about them. The edition you mentioned was published in March 2003, which is indeed fairly recent, so I would expect it to follow more modern conventions.

The code snippet you posted earlier should work fine (it compiles fine in VC6 for me, with the using namespace std; line and the includes changed to their modern versions) since all the input is coming from one type of stream and all the output is going to another type of stream. The problem arises when you read in data from two different types of streams or write data to two different types of streams.

Stylistically, I would argue that mixing cstdio and iostream is generally a bad idea, even in a case like this. Also, gets() is inherently unsafe, since the program would break if a line longer than 80 characters was entered. Hopefully, this was noted in the book. If not... eep. OMG | :OMG:

shawnsch wrote:
how am I supposed to learn this book of the stuff doesn't compile.

What was the compiler error? I'm curious, since, as I mentioned, I just tried it in VC6 and it compiled and ran. Here is the version I tried:

#include <iostream><br />
#include <cstdio><br />
<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
char str[80];<br />
<br />
cout << "Enter a string: ";<br />
gets(str); <br />
cout << "Here is your string: ";<br />
cout << str;<br />
<br />
return 0;<br />
}


- Mike
GeneralShould be easy... Pin
RobJones29-Sep-03 11:26
RobJones29-Sep-03 11:26 
GeneralRe: Should be easy... Pin
Dave Bryant29-Sep-03 11:33
Dave Bryant29-Sep-03 11:33 
GeneralRe: Should be easy... Pin
RobJones29-Sep-03 11:55
RobJones29-Sep-03 11:55 
GeneralGetModuleFileName instance and registering app Pin
Raymond So29-Sep-03 9:15
Raymond So29-Sep-03 9:15 
GeneralRe: GetModuleFileName instance and registering app Pin
Dave Bryant29-Sep-03 10:59
Dave Bryant29-Sep-03 10:59 
GeneralRe: GetModuleFileName instance and registering app Pin
igor196029-Sep-03 12:58
igor196029-Sep-03 12:58 
GeneralRe: GetModuleFileName instance and registering app Pin
Michael Dunn29-Sep-03 16:26
sitebuilderMichael Dunn29-Sep-03 16:26 
GeneralTaskbar window button Pin
blade29-Sep-03 9:01
blade29-Sep-03 9:01 
GeneralExecuting an EXE from memory Pin
Larry Antram29-Sep-03 8:54
Larry Antram29-Sep-03 8:54 
GeneralRe: Executing an EXE from memory Pin
David Crow29-Sep-03 11:14
David Crow29-Sep-03 11:14 
GeneralRe: Executing an EXE from memory Pin
Larry Antram29-Sep-03 12:23
Larry Antram29-Sep-03 12:23 
GeneralRe: Executing an EXE from memory Pin
Michael Dunn29-Sep-03 16:29
sitebuilderMichael Dunn29-Sep-03 16:29 
QuestionHow to create an &quot;Open With&quot; list? Pin
ralfoide29-Sep-03 8:45
ralfoide29-Sep-03 8:45 
AnswerRe: How to create an &quot;Open With&quot; list? Pin
Amit Dey29-Sep-03 13:33
Amit Dey29-Sep-03 13:33 
GeneralEasy question about formatting a string Pin
NewHSKid29-Sep-03 8:18
NewHSKid29-Sep-03 8:18 
GeneralRe: Easy question about formatting a string Pin
Ravi Bhavnani29-Sep-03 8:35
professionalRavi Bhavnani29-Sep-03 8:35 
GeneralRe: Easy question about formatting a string Pin
David Crow29-Sep-03 8:38
David Crow29-Sep-03 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.