1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting a truncated output! Plz help

Discussion in 'C++' started by sicba2222, Oct 5, 2008.

  1. sicba2222

    sicba2222 New Member

    Joined:
    Oct 5, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The code is working correctly. "char x;" defines x as a single character. Did you mean "string x;"?
     

Share This Page