Click here to Skip to main content
15,877,547 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
N a v a n e e t h30-Oct-09 19:46
N a v a n e e t h30-Oct-09 19:46 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
CaptainSeeSharp30-Oct-09 19:48
CaptainSeeSharp30-Oct-09 19:48 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
LunaticFringe30-Oct-09 19:47
LunaticFringe30-Oct-09 19:47 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
CaptainSeeSharp30-Oct-09 19:50
CaptainSeeSharp30-Oct-09 19:50 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
LunaticFringe30-Oct-09 19:55
LunaticFringe30-Oct-09 19:55 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
CaptainSeeSharp30-Oct-09 20:02
CaptainSeeSharp30-Oct-09 20:02 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
LunaticFringe30-Oct-09 20:14
LunaticFringe30-Oct-09 20:14 
GeneralRe: cin >> foo; Sometimes it doesn't take... Pin
Randor 30-Oct-09 22:31
professional Randor 30-Oct-09 22:31 
Hi Captain,

There is absolutely nothing C# can do that C++ cannot do. Your sample code is flawed. You are trying to put multiple bytes into a 1 byte container.

CaptainSeeSharp wrote:
There should be a way to enter a value of up to 255 in the console window and have it convert that string into its byte representation like .NET's Byte.Parse("255");


Like this?

string magic_SeeSharpBuffer;
cout << "Enter a byte:";
cin >> magic_SeeSharpBuffer;
BYTE b = atoi(magic_SeeSharpBuffer.c_str());


The design and theory of C# and .NET languages somewhat has roots in OLE/COM technologies. Your C# datatypes are similar to VARIANTS[^] where the datatype can be interchanged. The .NET languages discourage direct memory access and direct data conversions by the end-user. The .NET internel conversion code was written by an engineer at Microsoft and you rely on the IL instructions generated by him/her.

The C++ language gives the engineer more control over the datatype and memory. The C++ language trusts that you know what you are doing. It will allow you to write code that will blow-up and crash.

The Microsoft C++ compiler *could* detect these situations and throw a compile-time warning or error. But believe it or not sometimes C++ software developers *want* to overflow a buffer or overwrite memory. Thats exactly what makes the language so powerful. Its greatest strength and at the same time its weakness.

I am happy that you are experimenting with the C++ language. Don't get frustrated because eventually you will understand these fundemental concepts and will be a better software engineer because of it.

Best Wishes,
-David Delaune
QuestionLPCSTR and char* issues Pin
MbHimself30-Oct-09 17:34
MbHimself30-Oct-09 17:34 
AnswerRe: LPCSTR and char* issues [modified] Pin
LunaticFringe30-Oct-09 18:46
LunaticFringe30-Oct-09 18:46 
GeneralRe: LPCSTR and char* issues Pin
MbHimself30-Oct-09 19:09
MbHimself30-Oct-09 19:09 
GeneralRe: LPCSTR and char* issues Pin
LunaticFringe30-Oct-09 19:42
LunaticFringe30-Oct-09 19:42 
AnswerRe: LPCSTR and char* issues Pin
«_Superman_»30-Oct-09 19:40
professional«_Superman_»30-Oct-09 19:40 
Questionhow to use a matrix associeted to control variables ? Pin
timbk30-Oct-09 13:32
timbk30-Oct-09 13:32 
AnswerRe: how to use a matrix associeted to control variables ? Pin
«_Superman_»30-Oct-09 15:55
professional«_Superman_»30-Oct-09 15:55 
Questiondll linking Pin
rahul116730-Oct-09 6:31
rahul116730-Oct-09 6:31 
AnswerRe: dll linking Pin
Richard MacCutchan30-Oct-09 6:55
mveRichard MacCutchan30-Oct-09 6:55 
QuestionRe: dll linking Pin
David Crow30-Oct-09 7:42
David Crow30-Oct-09 7:42 
AnswerRe: dll linking Pin
rahul116730-Oct-09 20:26
rahul116730-Oct-09 20:26 
GeneralRe: dll linking Pin
Cedric Moonen30-Oct-09 23:25
Cedric Moonen30-Oct-09 23:25 
GeneralRe: dll linking Pin
David Crow2-Nov-09 3:35
David Crow2-Nov-09 3:35 
QuestionProblem while using CComBSTR Pin
Rahul Vaishnav30-Oct-09 5:37
Rahul Vaishnav30-Oct-09 5:37 
AnswerRe: Problem while using CComBSTR Pin
Rahul Vaishnav30-Oct-09 17:57
Rahul Vaishnav30-Oct-09 17:57 
QuestionJET / ADO - Windows 7 Pin
Robert Valentino30-Oct-09 4:55
Robert Valentino30-Oct-09 4:55 
QuestionBreadth First Search Algorithm in C Pin
mossy46430-Oct-09 4:50
mossy46430-Oct-09 4:50 

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.