Click here to Skip to main content
15,898,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: cin issue Pin
Programm3r13-Mar-07 8:57
Programm3r13-Mar-07 8:57 
QuestionRe: cin issue Pin
David Crow13-Mar-07 9:16
David Crow13-Mar-07 9:16 
AnswerRe: cin issue Pin
CPallini13-Mar-07 10:05
mveCPallini13-Mar-07 10:05 
GeneralRe: cin issue Pin
Cedric Moonen13-Mar-07 10:32
Cedric Moonen13-Mar-07 10:32 
GeneralRe: cin issue Pin
CPallini13-Mar-07 12:11
mveCPallini13-Mar-07 12:11 
GeneralRe: cin issue Pin
Stephen Hewitt13-Mar-07 15:43
Stephen Hewitt13-Mar-07 15:43 
GeneralRe: cin issue Pin
CPallini13-Mar-07 21:52
mveCPallini13-Mar-07 21:52 
AnswerRe: cin issue Pin
Stephen Hewitt13-Mar-07 15:39
Stephen Hewitt13-Mar-07 15:39 
Some advice:
  Don't use char arrays like you're doing. If the string is too long you'll overflow the array and corrupt the stack. Debugging stack corruptions is hard. Instead use std::strings. e.g.
// CommandLine.cpp : Defines the entry point for the console application.
//
 
#include "StdAfx.h"
#include <string>
#include <iostream>
 
int main()
{
	using namespace std;
 
	string s;
	cout << "Please enter your name: ";
	cin >> s;
	cout << "Hello " << s << "!" << endl;
 
	return 0;
}


If you must use raw chars the use the setw manipulator. i.e.
// CommandLine.cpp : Defines the entry point for the console application.
//
 
#include "StdAfx.h"
#include <iostream>
#include <iomanip>
 
int main()
{
	using namespace std;
 
	char s[4];
	cout << "Please enter your name: ";
	cin >> setw(sizeof(s)) >> s;
	cout << "Hello " << s << "!" << endl;
 
	return 0;
}



Steve

GeneralRe: cin issue Pin
Programm3r13-Mar-07 19:45
Programm3r13-Mar-07 19:45 
QuestionMFC - CBitmap BitBlt Pin
Rajesh Rajan Pankapattu13-Mar-07 7:32
Rajesh Rajan Pankapattu13-Mar-07 7:32 
AnswerRe: MFC - CBitmap BitBlt Pin
lafleon13-Mar-07 11:55
lafleon13-Mar-07 11:55 
Questionhow to add 24 bit color icons in VS.net editor Pin
OmarLodhi13-Mar-07 5:43
OmarLodhi13-Mar-07 5:43 
GeneralRe: how to add 24 bit color icons in VS.net editor Pin
Programm3r13-Mar-07 5:46
Programm3r13-Mar-07 5:46 
AnswerRe: how to add 24 bit color icons in VS.net editor Pin
Mark Salsbery13-Mar-07 7:10
Mark Salsbery13-Mar-07 7:10 
QuestionWeb services and win 32 Pin
LCI13-Mar-07 5:25
LCI13-Mar-07 5:25 
AnswerRe: Web services and win 32 Pin
led mike13-Mar-07 5:41
led mike13-Mar-07 5:41 
GeneralRe: Web services and win 32 Pin
LCI13-Mar-07 5:48
LCI13-Mar-07 5:48 
GeneralRe: Web services and win 32 Pin
led mike13-Mar-07 7:03
led mike13-Mar-07 7:03 
GeneralRe: Web services and win 32 Pin
Mark Salsbery13-Mar-07 7:26
Mark Salsbery13-Mar-07 7:26 
GeneralRe: Web services and win 32 Pin
led mike13-Mar-07 7:45
led mike13-Mar-07 7:45 
AnswerRe: Web services and win 32 Pin
led mike14-Mar-07 6:23
led mike14-Mar-07 6:23 
GeneralRe: Web services and win 32 Pin
LCI14-Mar-07 6:26
LCI14-Mar-07 6:26 
GeneralRe: Web services and win 32 Pin
LCI14-Mar-07 6:31
LCI14-Mar-07 6:31 
GeneralRe: Web services and win 32 Pin
led mike14-Mar-07 7:03
led mike14-Mar-07 7:03 
GeneralRe: Web services and win 32 Pin
LCI14-Mar-07 9:42
LCI14-Mar-07 9:42 

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.