Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing a string of user input to a function is blank

Posted on 2004-10-25
4
Medium Priority
?
219 Views
Last Modified: 2010-04-17
cout<<"Please enter a cities name in Ohio begining with the letter S"<<"\n";
      cin>>temp.city_name;
      getline(cin, temp.city_name);
      Search_hash_table(temp, count, vec1);
I am sorry to bother everyone but I am stuck. If I wanted to pass the input string of user input to the search_hash and temp is my struct isn't this how I would do it? The reason I am asking because the search function is outputing a blank city_name and I have even debugged by putting in a cout and it is blank. What the heck am I missing? Thanks
0
Comment
Question by:Corey_819
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Accepted Solution

by:
HerrMyrslok earned 100 total points
ID: 12403797
Well it could be because you're reading twice into temp.city_name.
when you do getline(cin, temp.city_name); you're overwriting whatever you received on the line above.
Try to remove either
cin>>temp.city_name;
or
getline(cin,temp.city_name);
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12403842
What datatype is city_name?

Which should read in the name?
     cin>>temp.city_name;                      //Read in the name?
OR
     getline(cin, temp.city_name);            //Read in the name or the name plus newline or just newline
0
 
LVL 3

Expert Comment

by:HendrikTYR
ID: 12403880
Hi,

If temp.city_name is a character array (char[]) then use :
cin>>temp.city_name;

... but if it is a "string" then use :
getline(cin, temp.city_name);

Don't put both lines in your code.

Regards
Hendrik
0
 
LVL 1

Author Comment

by:Corey_819
ID: 12403881
Sorry I wish I had more points to give you both. Why was some of the website c++ fourms using both cin and getline that is now why I am confused? Thank you so much.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question