Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-2006, 06:27 PM
Ronin Ronin is offline
Programming Professional
 
Join Date: Apr 2006
Posts: 299
Rep Power: 10
Ronin is on a distinguished road
Default Only first name

I use this:

Code:
string name;
cin >> name;
but when the user enters "Jane Doe" the name string only contains "Jane". How can I fix this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-09-2006, 11:37 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 1,953
Last Blog:
NaNoWriMo Day 15
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

try using cin.getline(name)
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-12-2006, 06:47 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 104
Rep Power: 8
icepack is on a distinguished road
Send a message via AIM to icepack
Default

or use
#include <string>


and then, declare your string like

string str1;

cout << "Enter the name blah blah:\n";
getline(cin, str1);

should work fine

Last edited by icepack; 11-12-2006 at 06:47 PM. Reason: find vs. fine
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-13-2006, 12:39 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 13
Crane is on a distinguished road
Default

The space is causing cin >> to terminate. Using the getline like suggested will read until a linebreak.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 10:01 AM.

Contest Stats

John ........ 203.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 63%

Ads