473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Inserting a space in C++

How can I allow a user (in a command prompt) to enter a string of
characters and put spaces in it? I use Dev C++. Example:

char[50] google;

cin>> google;
Whenever I try this and output the variable, the string cuts off at the
end of a space. The odd thing is that the alt code space works, but not
the spacebar.

Apr 12 '06 #1
4 18238
ir******@gmail.com wrote:
How can I allow a user (in a command prompt) to enter a string of
characters and put spaces in it? I use Dev C++. Example:

char[50] google;
Do you mean

char google[50];

? Never mind...
cin>> google;
Whenever I try this and output the variable, the string cuts off at
the end of a space. The odd thing is that the alt code space works,
but not the spacebar.


Use 'std::getline'. RTFM about it.

V
--
Please remove capital As from my address when replying by mail
Apr 12 '06 #2

ir******@gmail.com wrote:
How can I allow a user (in a command prompt) to enter a string of
characters and put spaces in it? I use Dev C++. Example:

char[50] google;
I doubt if any compiler accepts this. Try posting correct code snippet.
You probably meant
char google[50];
cin>> google;
Try:
char a[50];
std::cin.getline(a, 50);
std::cout<<a;


Whenever I try this and output the variable, the string cuts off at the
end of a space. The odd thing is that the alt code space works, but not
the spacebar.


Actually why not use string ?

std::string a;
std::getline(std::cin, a);
std::cout<<a;

Apr 12 '06 #3
A String also doesn't work

Apr 22 '06 #4

ir******@gmail.com wrote:
A String also doesn't work


Please quote some context in your message. To do so from Google Groups,
see this link
http://cfaj.freeshell.org/google/

Victor and Jaspreet both suggested reading into a std::string using
std::getline. That will do what you want. On the other hand, this

std::string s;
std::cin << s;

will have exactly the same problem as your original code (although it
is better than your original code for a different reason). If you can't
get std::getline to do what you want, this link explains how to get
help here.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Gavin Deane

Apr 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mechphisto | last post by:
I'm using a textarea to insert some notes into a database. It's inserting the complete result into the mySQL table including the linebreaks...and not as a visible symbol but an actual linebreak. If...
1
by: Chris Sharman | last post by:
Writing a form, several questions have got a list of checkboxes, with associated descriptions (mostly one word), all on a line. Eg: Describe yourself: Fat Hairy Ugly Wears glasses. I want to...
4
by: epaetz | last post by:
I'm doing a bcp out of a table to a file. Some of the fields in a record may have an empty string. When I bcp out to the file and examine it, the fields that have an empty string in the database...
4
by: Mesan | last post by:
Here's the question: How do you get DB2 to update a char(n) field with multiple spaces right next to each other without having the additional spaces being omitted? Here's the background: We...
2
by: Darren | last post by:
Hi All, This will probably have the easiest solution but as I'm still a newbie and need some help... When building a query I would like to create a field called Name which includes both the...
8
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a...
1
by: Sailer, Denis | last post by:
There was a posting in the mailing list archives that I can't find anymore. The web site right now is presenting a list of items from a search in a reasonable amount of time, but takes 5-10 minutes...
7
by: Astra | last post by:
Hi All Can you please help me with a few queries on adding a header line and padding rows out. I apologise profusely for not providing the DDL for this, but I don't have it. All I have is...
7
by: MaxMax | last post by:
I want to insert a white line between XML elements to raise human readability example: <MyNode> </MyNode> <MyNode> </MyNode>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.