954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

redundant variables

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?

3246251196
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

>cannt you pass the CONSOLE_INPUT straight into the function?
Not the way you want to do it, no.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

cin returns itself, not the thing(s) it reads from the input.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
cannt you pass the CONSOLE_INPUT straight into the function?

Why do you WANT to do that.....?

If anything what is wrong with...

function(cin.getline(...));


...will grab the input and pass it to the function.

1o0oBhP
Posting Pro in Training
445 posts since Dec 2004
Reputation Points: 16
Solved Threads: 6
 

>...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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Why do you WANT to do that.....?

If anything what is wrong with...

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)

3246251196
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You