C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 25th, 2006, 06:56 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
Strings input

is there any way to include whitespace in string inputs without using character arrays ?
without using this ?
char name[50]
getline(name,50); ?


cout<<"enter first and last name";
cin>>name

cout<<name

"John Smith"

Reply With Quote
  #2  
Old April 25th, 2006, 08:04 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
use this
Code:
string str;
getline(cin,str);

this should work fine as long as you have a newer compiler.
__________________
---Official Member Of The Itsacon Fan Club---
Give a man a fish and he will eat for a day. Teach a man to fish and he will sit in a boat all day drinking beer.

Reply With Quote
  #3  
Old April 27th, 2006, 04:21 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
dev -C++ from bloodshed.net fall into that "newer compiler" category?

Reply With Quote
  #4  
Old April 27th, 2006, 11:38 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Yes that should do fine, thats the one I use and it works properly. Just plug that in and see what you get. Just add a cout<<str<<endl; to print the results.

Reply With Quote
  #5  
Old April 29th, 2006, 02:59 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
hey since you use that maybe you could help me with a problem, everytime i compile something after it outputs, the dos window automatically closes, how do i set it to where it asks to press any key to manually close the dos window like visual basic c++ ?

Reply With Quote
  #6  
Old April 30th, 2006, 12:54 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
The reason being is because after your code is finished the program sends a return 0; to the computer which in short means everything went ok, so close. If you put a system("PAUSE"); in there or another cin>> statement in there it will pause until the user says so. For example.
Code:
int main()
{
char ch;
string str;

cout<<"Enter some text\n";
getline(cin,str);
cout<<"You entered:\n";
cout<<str<<endl;
cout<<"Would you like to exit the program now? (Y/N) : ";
cin>>ch;
if(ch == 'N' || ch == 'n')
{
return 0;
}
else
{
cout<<"Oh well Im closing anyways, he he\n";
}
cout<<"Now look at what system(\"PAUSE\") does \n";
system ("PAUSE");
return 0;
}

here is an example that shows two ways to exit a program without it closing automatically on you.

Reply With Quote
  #7  
Old May 1st, 2006, 03:42 AM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
coo thanx

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Strings input


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT