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

easy question part 2

max
Hi,
I've tried the std::getline and std::string. It seams to work but I get
some tourbles with it. WIth the folowing code:

if(ne_menu=='4')
{
cout << "Nom du Client/Projet:";
getline(std::cin,estime_nom);
nouv_estime();
}

when ne_menu is equal to 4 it just steps right to nouv_estime without
asking anything... What do I do wrong??
Jul 19 '05 #1
8 1410

"max" <ma*@localhost.ca> wrote in message news:pa****************************@localhost.ca.. .
Hi,
I've tried the std::getline and std::string. It seams to work but I get
some tourbles with it. WIth the folowing code:

if(ne_menu=='4')
{
cout << "Nom du Client/Projet:";
getline(std::cin,estime_nom);
nouv_estime();
}

when ne_menu is equal to 4 it just steps right to nouv_estime without
asking anything... What do I do wrong??


Well you didn't bother showing us the rest of the code, but I suspect
that you showed him:

char ne_menu;
cin >> ne_menu;

before.

The problem is that you read one character, but you left a newline in the buffer.
That immediately gets eaten by getline. You can either do cin.ignore() to eat
the rest of the line, or use getline for reading ne_menu rather than just a char.
Jul 19 '05 #2
max
On Tue, 21 Oct 2003 18:03:11 -0400, Ron Natalie wrote:
Hi,
I think I didn't put a good example, all I want to do is this to work (
e.g. )

std::string hello;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

So how can you make this work?

"max" <ma*@localhost.ca> wrote in message
news:pa****************************@localhost.ca.. .
Hi,
I've tried the std::getline and std::string. It seams to work but I get
some tourbles with it. WIth the folowing code:

if(ne_menu=='4')
{
cout << "Nom du Client/Projet:";
getline(std::cin,estime_nom);
nouv_estime();
}
}
when ne_menu is equal to 4 it just steps right to nouv_estime without
asking anything... What do I do wrong??


Well you didn't bother showing us the rest of the code, but I suspect
that you showed him:

char ne_menu;
cin >> ne_menu;

before.

The problem is that you read one character, but you left a newline in
the buffer. That immediately gets eaten by getline. You can either do
cin.ignore() to eat the rest of the line, or use getline for reading
ne_menu rather than just a char.


Jul 19 '05 #3
max
On Tue, 21 Oct 2003 18:56:13 -0400, max wrote:
god damnit wrong var name!
std::string hello; should be name insted of hello!! std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !
On Tue, 21 Oct 2003 18:03:11 -0400, Ron Natalie wrote:
Hi,
I think I didn't put a good example, all I want to do is this to work (
e.g. )

std::string hello;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

So how can you make this work?

"max" <ma*@localhost.ca> wrote in message
news:pa****************************@localhost.ca.. .
Hi,
I've tried the std::getline and std::string. It seams to work but I get
some tourbles with it. WIth the folowing code:

if(ne_menu=='4')
{
cout << "Nom du Client/Projet:";
getline(std::cin,estime_nom);
nouv_estime();
}
}
when ne_menu is equal to 4 it just steps right to nouv_estime without
asking anything... What do I do wrong??


Well you didn't bother showing us the rest of the code, but I suspect
that you showed him:

char ne_menu;
cin >> ne_menu;

before.

The problem is that you read one character, but you left a newline in
the buffer. That immediately gets eaten by getline. You can either do
cin.ignore() to eat the rest of the line, or use getline for reading
ne_menu rather than just a char.


Jul 19 '05 #4
Please don't top-post. Fixed.

max wrote:
On Tue, 21 Oct 2003 18:56:13 -0400, max wrote:
On Tue, 21 Oct 2003 18:03:11 -0400, Ron Natalie wrote:
Hi,
I think I didn't put a good example, all I want to do is this to work
( e.g. )


god damnit wrong var name!
std::string hello;


should be name insted of hello!!
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !
std::string hello;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

So how can you make this work?


#include <iostream>
#include <string>

int main()
{
std::string name;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

std::cout << std::endl;
}
Works fine for me. Which problem do you get with it?

Jul 19 '05 #5
max
On Wed, 22 Oct 2003 01:15:50 +0200, Rolf Magnus wrote:

Yes me too but I didn't realize my problem was that when you enter
somthing like "Mr Max" it only takes "Mr" in your var and max stay for
another CIN further. What's the prob?
Please don't top-post. Fixed.

max wrote:
On Tue, 21 Oct 2003 18:56:13 -0400, max wrote:
On Tue, 21 Oct 2003 18:03:11 -0400, Ron Natalie wrote:
Hi,
I think I didn't put a good example, all I want to do is this to work
( e.g. )


god damnit wrong var name!
std::string hello;


should be name insted of hello!!
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !
std::string hello;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

So how can you make this work?


#include <iostream>
#include <string>

int main()
{
std::string name;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

std::cout << std::endl;
}
Works fine for me. Which problem do you get with it?


Jul 19 '05 #6


max wrote:

On Wed, 22 Oct 2003 01:15:50 +0200, Rolf Magnus wrote:

Yes me too but I didn't realize my problem was that when you enter
somthing like "Mr Max" it only takes "Mr" in your var and max stay for
another CIN further. What's the prob?


First of all:
Please don't top post. The code you are referring to is at the end of you
reply, thus to compare your diagnostics with the code it refers to, we need
to constantly scroll up and down. Put your reply beneath the section
you are replying to, such as I did now. And snip the sections you
don't need in your reply.
If you are too lazy to come up with an easy to read reply, where
the things are in context and chronological order then we
will be too lazy to try to help you. It's as simple as that.

[snip]

#include <iostream>
#include <string>

int main()
{
std::string name;
std::cout << "Please enter your name:";
std::getline(std::cin,name);
std::cout << "Hello, " << name << " !";

std::cout << std::endl;
}
Works fine for me. Which problem do you get with it?


When entering 'Mr Max' at the prompt, name should contain
the string 'Mr Max'. The diagnostics you showed is the normal
behaviour, if you did:

std::cin >> name;

instead of

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

Are you sure this is not the problem?

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #7
max wrote:
On Wed, 22 Oct 2003 01:15:50 +0200, Rolf Magnus wrote:

Yes me too but I didn't realize my problem was that when you enter
somthing like "Mr Max" it only takes "Mr" in your var and max stay for
another CIN further. What's the prob?


Hint: the std::getline has a third parameter that is the delimiter
between reads, by default is an space. This is the cause of this behaviour.

Jul 19 '05 #8


Juan Antonio Domínguez Pérez wrote:

max wrote:
On Wed, 22 Oct 2003 01:15:50 +0200, Rolf Magnus wrote:

Yes me too but I didn't realize my problem was that when you enter
somthing like "Mr Max" it only takes "Mr" in your var and max stay for
another CIN further. What's the prob?


Hint: the std::getline has a third parameter that is the delimiter
between reads, by default is an space. This is the cause of this behaviour.


Are you sure you know what you are talking about?
The standard default delimiter for getline equals '\n', not space.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #9

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

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
2
by: abs | last post by:
Here's my page containing problematic alghoritm which seems to be easy but I have some problems with it: http://tinyurl.com/a2v58 The trouble is that when I click on element which has yellow...
3
by: zn | last post by:
I need to implement a sales section on our company website to sell products direct to consumers. We have to do this in short order but I have very little html and no php experience. Our platform is...
2
by: Thomas | last post by:
Hi, I there anybody here that are designing applications with asp.net without html in aspx files? The problem is that aspx files is a dependency, and I would like to avoid having that...
7
by: SteveM | last post by:
I am sure this is an easy question, but being relatively new to ASP.NET programming, I can not quite grasp what I need to accomplish what I need to do. What I have is a word document that is...
6
cjbrx3115
by: cjbrx3115 | last post by:
Hey everyone, I just bought a new Windows Vista (Home Premium) computer. My old computer, a Windows XP Professional, had all of my old documents, spreadsheets, etc. I was planing on using the Easy...
3
by: tvance929 | last post by:
Ok, I am creating a string to go into a RTB. Is there any code or tags I can create within the string so that I can Bolden or Italicize certain words? I would normally assume no way until I...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
14
by: Naraendirakumar R.R. | last post by:
I have a client in the healthcare industry who would prefer to store the connection string in a centralized location in their Active Directory repository. Has anybody done this? What has your...
1
by: Michael Torrie | last post by:
Recently a post that mentioned a recipe that extended subprocess to allow killable processes caused me to do some thinking. Some of my larger bash scripts are starting to become a bit unwieldy...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
tracyyun
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 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.