Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Getting a truncated output! Plz help (http://www.go4expert.com/forums/getting-truncated-output-plz-help-t14381/)

sicba2222 5Oct2008 16:58

Getting a truncated output! Plz help
 
Hi all,

I am new to the forum and to learning C++. I tried a simple program to input one's name and display them (using cin). Here is the code...




#include "stdafx.h"
#include<iostream>

int main()
{
char x;
using namespace std;
cout << "To explain the cin function";
cout << "Enter your name:";
cin >> x;
cout << "You entered" << x << endl;

}

But I get a truncated output. For instance, if I enter a name like "Rajesh" I get the output as "You entered: R"...rest of the name is gone. I usd Microsoft Visual C++ 2005 express edition...Could any of you explain this to me?? Thank you in advance.

xpi0t0s 6Oct2008 15:12

Re: Getting a truncated output! Plz help
 
The code is working correctly. "char x;" defines x as a single character. Did you mean "string x;"?


All times are GMT +5.5. The time now is 13:02.