473,387 Members | 1,611 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,387 software developers and data experts.

cin and spaces

Hi,
I'm trying to use cin to capture some input from the console, but it always
seems to consider a space as the end of the string. I tried to use
cin.getline() but it only works for char arrays, and I would rather use
strings. At the moment, I'm using getline to read the input into a char
array and I'm then making a string out of it. Is there a more elegant way of
doing this?
Thanks in advance,
S. Armondi

--
To contact me by email, remove _NOSPAM_ from the address.
Jul 19 '05 #1
2 18420
"Samuele Armondi" <sa****************@hotmail.com> wrote...
I'm trying to use cin to capture some input from the console, but it always seems to consider a space as the end of the string. I tried to use
cin.getline() but it only works for char arrays, and I would rather use
strings. At the moment, I'm using getline to read the input into a char
array and I'm then making a string out of it. Is there a more elegant way of doing this?


std::getline(std::cin, somestring);

V
Jul 19 '05 #2

"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vf************@corp.supernews.com...
"Samuele Armondi" <sa****************@hotmail.com> wrote...
I'm trying to use cin to capture some input from the console, but it always
seems to consider a space as the end of the string. I tried to use
cin.getline() but it only works for char arrays, and I would rather use
strings. At the moment, I'm using getline to read the input into a char
array and I'm then making a string out of it. Is there a more elegant

way of
doing this?


std::getline(std::cin, somestring);

V

Thank you!
Jul 19 '05 #3

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

Similar topics

2
by: Michael Bulatovich | last post by:
I have a simple db to keep track of work/time/projects etc. It has two fields (column) named "start time" and "end time" WITH THE SPACES. I'm trying to do some automation to a form associated with...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
3
by: Luke - eat.lemons | last post by:
Hi, Could someone tell me the correct quotation to get around spaces in paths for: Server.MapPath("\\server\share\spaces in name.mdb") I know its bad practice to use spaces but...
8
by: Joe Cool | last post by:
I need to map several columns of data from one database to another where the data contains multiple spaces (once occurance of a variable number or spaces) that I need to replace with a single...
3
by: bstjean | last post by:
Hi everyone, I am trying to find an efficient way to perform a special query. Let me explain what I want. Let's say we are looking for all description that match "this is the target". In...
5
by: brian.j.parker | last post by:
Hey all, I've noticed an obscure little quirk: it appears that if you use a login with trailing spaces on the name, SYSTEM_USER automatically trims those trailing spaces in SQL Server 2000, but not...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.