This is very strange. In the following program, If I type a one-word
name, it works fine. Now, if I type a two-word name, the program splits
the variable into two:
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? ";
std::string name;
std::cin >name;
std::cout << "Hello, " << name
<< std::endl << "And what is yours? ";
std::cin >name;
std::cout << "Hello, " << name
<< "; nice to meet you too!" << std::endl;
return 0;
}
Do you know why?
Thanks. 6 2266
"Charles" <la********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com
This is very strange. In the following program, If I type a one-word
name, it works fine. Now, if I type a two-word name, the program
splits the variable into two:
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? ";
std::string name;
std::cin >name;
std::cout << "Hello, " << name
<< std::endl << "And what is yours? ";
std::cin >name;
std::cout << "Hello, " << name
<< "; nice to meet you too!" << std::endl;
return 0;
}
Do you know why?
Thanks.
See the description of the >operator in details on p.15.
--
John Carson
Charles wrote:
This is very strange. In the following program, If I type a one-word
name, it works fine. Now, if I type a two-word name, the program splits
the variable into two:
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? ";
std::string name;
std::cin >name;
std::cout << "Hello, " << name
<< std::endl << "And what is yours? ";
std::cin >name;
std::cout << "Hello, " << name
<< "; nice to meet you too!" << std::endl;
return 0;
}
Do you know why?
Thanks.
When you read a string from cin via operator>>, the delimiter is
whitespace. Each operator>will
stop after a whitespace, while the next operator>will ignore
whitespace and continue parsing the
input.
so, if I type;
tolga ceylan<return>
then the first operator>gets "tolga"
and stops at whitespace. The next operator>will skip whitespace and
get "ceylan" and stop at <return>
Hope this helps,
Tolga Ceylan to***********@yahoo.com wrote:
Charles wrote:
This is very strange. In the following program, If I type a one-word
name, it works fine. Now, if I type a two-word name, the program splits
the variable into two:
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? ";
std::string name;
std::cin >name;
std::cout << "Hello, " << name
<< std::endl << "And what is yours? ";
std::cin >name;
std::cout << "Hello, " << name
<< "; nice to meet you too!" << std::endl;
return 0;
}
Do you know why?
Thanks.
When you read a string from cin via operator>>, the delimiter is
whitespace. Each operator>will
stop after a whitespace, while the next operator>will ignore
whitespace and continue parsing the
input.
so, if I type;
tolga ceylan<return>
then the first operator>gets "tolga"
and stops at whitespace. The next operator>will skip whitespace and
get "ceylan" and stop at <return>
Hope this helps,
Tolga Ceylan
What exactly happened and why did she leave Tulsa for Melbourne? to***********@yahoo.com escreveu:
When you read a string from cin via operator>>, the delimiter is
whitespace. Each operator>will
stop after a whitespace, while the next operator>will ignore
whitespace and continue parsing the
input.
so, if I type;
tolga ceylan<return>
then the first operator>gets "tolga"
and stops at whitespace. The next operator>will skip whitespace and
get "ceylan" and stop at <return>
Hope this helps,
Thanks, ah ok, I didn't grasp that...Interesting. Now I know!
Mathematician wrote:
What exactly happened and why did she leave Tulsa for Melbourne?
This is a C++ book not a place for human relationship questions. It's
private you should stop!
---*---*---*----*--------*********---------------***************
Dear ladies and gentlemen, please forgive mathematician for his curios
question, really sorry about that..
But if you know the reasons, I think others might also want to hear a
litle to***********@yahoo.com wrote:
Charles wrote:
This is very strange. In the following program, If I type a one-word
name, it works fine. Now, if I type a two-word name, the program splits
the variable into two:
#include <iostream>
#include <string>
int main()
{
std::cout << "What is your name? ";
std::string name;
std::cin >name;
std::cout << "Hello, " << name
<< std::endl << "And what is yours? ";
std::cin >name;
std::cout << "Hello, " << name
<< "; nice to meet you too!" << std::endl;
return 0;
}
Do you know why?
Thanks.
When you read a string from cin via operator>>, the delimiter is
whitespace. Each operator>will
stop after a whitespace, while the next operator>will ignore
whitespace and continue parsing the
input.
so, if I type;
tolga ceylan<return>
then the first operator>gets "tolga"
and stops at whitespace. The next operator>will skip whitespace and
get "ceylan" and stop at <return>
Hope this helps,
Tolga Ceylan
Default delimiter is Whitespace! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Slonocode |
last post by:
Hello I am trying to display a USA address properly in a multiline textbox.
Unfortunately the address I must process is contained in a string variable
and the format is not uniform.
Examples:
...
|
by: simonc |
last post by:
One of the things that drives me mad about vb.net is
spending time trying to make a program do something then
finding that there's already an inbuild procedure that
does exactly the same thing.
...
|
by: HappyHippy |
last post by:
More of a minor niggle than anything but how would I remove the
aforementioned space?
eg.
strName = 'World'
print 'Hello', strName, ', how are you today?'
comes out as "Hello World , how are...
|
by: Daren |
last post by:
Hi,
I need to be able to split large string variables into an array of
lines, each line can be no longer than 70 chars.
The string variables are text, so I would additionally like the lines...
|
by: moostafa |
last post by:
Hi,
I'm writing a program that performs arithmetic operations on integers.
I want to be able to type in a bunch of integers seperated by any
amount of white space then terminate input with a...
| |
by: Sriram Rajagopalan |
last post by:
Hi,
I was interested to know if there is a way to use a variable name split
across multiple lines in C.
For example :
int this_is_a_very_long_variable_name = 10;
I would like to split...
|
by: garyusenet |
last post by:
I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross...
|
by: skyy |
last post by:
Hi.. i have a string that i would want split on a single blank space only.
eg.
$string = File: abc.txt
using split with white space i can get the name of the file : abc.txt
However i run...
|
by: ganesh gajre |
last post by:
Hi all,
I want to read file which is mapping file. Used in to map character from ttf
to unicode.
eg
Map file contain data in the following way:
0 ०
1 १
|
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...
|
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,...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |