944,120 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1803
  • C++ RSS
Jan 20th, 2005
0

redundant variables

Expand Post »
take a look at this code:

---
void redundant_var()
{
char user_name[]="";
cout<<"insert name: "; cin>>user_name;
swap_name(user_name); //another function not seen
}
---

now, the following code works fine, but i am SURE there is a away to pass in user_name without the need of storing it in a temporary variable.

cannt you pass the CONSOLE_INPUT straight into the function?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3246251196 is offline Offline
2 posts
since Jan 2005
Jan 20th, 2005
0

Re: redundant variables

>cannt you pass the CONSOLE_INPUT straight into the function?
Not the way you want to do it, no.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jan 20th, 2005
0

Re: redundant variables

cin returns itself, not the thing(s) it reads from the input.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jan 20th, 2005
0

Re: redundant variables

Quote ...
cannt you pass the CONSOLE_INPUT straight into the function?
Why do you WANT to do that.....?

If anything what is wrong with...
C++ Syntax (Toggle Plain Text)
  1. function(cin.getline(...));

...will grab the input and pass it to the function.
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004
Jan 20th, 2005
0

Re: redundant variables

>...will grab the input and pass it to the function.
Be more specific or I'll have to describe in detail why you're wrong. Since you've proven yourself to know C++ fairly well, I'll give you the benefit of the doubt and assume that you just worded your post poorly.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jan 21st, 2005
0

Re: redundant variables

Quote originally posted by 1o0oBhP ...
Why do you WANT to do that.....?

If anything what is wrong with...
C++ Syntax (Toggle Plain Text)
  1. function(cin.getline(...));

...will grab the input and pass it to the function.
ok thats excellent:

"swap_name(cin.getline());"

or does something have to go int the parenthesis (which i am confident does)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
3246251196 is offline Offline
2 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I need your suggestions in learning Language
Next Thread in C++ Forum Timeline: Overloading matrix bracket operators





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC