Basically, I hate functions.... a little more help, if you would.....

H

HED

Ok still a student who is basically teaching himself.... I am haveing
some touble getting how functions work, but I have figured SOME of it
out. (about 1/10 of 1%) My program has this function in it, and
after it is compiling it is telling me "c:\documents and settings\us
\my documents\visual studio 2005\projects
\assingment1\assingment1\assingment4a.cpp(45) : error C3861:
'getline': identifier not found"

huh? I have used getline before in the same format (I even checked
previous assingments), but I do not understand why it is doing that.

string getname()
{
string username;
cout<<"Please enter your name"<<endl;
getline (cin, username);
return username;
}

My other problem is " error C2448: 'menu' : function-style initializer
appears to be a function definition"

I thought i spoke pretty fluent geek until i started trying to debug
my programs.....

I do not understand what it is telling me. Menu is a void function,
but I am (I think/hope) trying to put a string in it, so it looks
like:

void menu(name)
{

cout<<"Welcome, "<<name<<", where would you like to go?"<<endl;
cout<<"Please select a destination:"<<endl;
cout<<"A. Natural History Museum"<<endl;
cout<<"B. French Bistro"<<endl;
cout<<"C. Art Gallerey"<<endl;
cout<<"D. Bookshop"<<endl;
cout<<"E. Concert"<<endl;


}

Earlier I was trying to get the places to be arguments, but that was
not working. I think I partially understand how to do that now. i.e.
instead of

cout<<"A. Natural History Museum"<<endl;

it will read

cout<<"A. "<<placea<<endl;


Sorry, my questions are:
1. why doesnt getline work, and how can I make it work
and
2. what does "function-style initializer appears to be a function
definition" mean?

Again, thanks in advance.
 
G

Guest

Ok still a student who is basically teaching himself.... I am haveing
some touble getting how functions work, but I have figured SOME of it
out. (about 1/10 of 1%) My program has this function in it, and
after it is compiling it is telling me "c:\documents and settings\us
\my documents\visual studio 2005\projects
\assingment1\assingment1\assingment4a.cpp(45) : error C3861:
'getline': identifier not found"

huh? I have used getline before in the same format (I even checked
previous assingments), but I do not understand why it is doing that.

string getname()
{
string username;
cout<<"Please enter your name"<<endl;
getline (cin, username);
return username;
}

The getline() function is declared in <string>, so either you have not
included <string> or you have used 'using std::string;' earlier but not
done so for std::getline(). My advice would be to not use using
declarations or using directives since the extra typing is quite low and
you run the risk of getting into problems.
My other problem is " error C2448: 'menu' : function-style initializer
appears to be a function definition"

I thought i spoke pretty fluent geek until i started trying to debug
my programs.....

I do not understand what it is telling me. Menu is a void function,
but I am (I think/hope) trying to put a string in it, so it looks
like:

void menu(name)

What is the type of name? This should probably be

void menu(const std::string& name)
 
N

Nick Keighley

Subject: "Basically I hate functions..."

well you aren't going to do much programming without them...
Learn to live with them. Think of them as little programs.


Ok still a student who is basically teaching himself.... I am haveing
some touble getting how functions work, but I have figured SOME of it
out. (about 1/10 of 1%) My program has this function in it, and
after it is compiling it is telling me "c:\documents and settings\us
\my documents\visual studio 2005\projects
\assingment1\assingment1\assingment4a.cpp(45) : error C3861:
'getline': identifier not found"

huh? I have used getline before in the same format (I even checked
previous assingments), but I do not understand why it is doing that.

string getname()
{
string username;
cout<<"Please enter your name"<<endl;
getline (cin, username);
return username;

}

This compiles- compare it with your version

#include <string>
#include <iostream>

using namespace std;

string getname()
{
string username;
cout << "Please enter your name" << endl;
getline (cin, username);
return username;
}

int main ()
{
string name;
name = getname();
return 0;
}


I'm not claiming the style is good (try to avoid
"using namespace std"). Returning a string by value can be expensive.


My other problem is " error C2448: 'menu' : function-style initializer
appears to be a function definition"

get into the habbit of posting (small) complete programs.
I can't see what's wrong with what you've posted, but
it is incomplete.

I thought i spoke pretty fluent geek until i started trying to debug
my programs.....

you've barely scratched the surface... :)

I do not understand what it is telling me. Menu is a void function,
but I am (I think/hope) trying to put a string in it, so it looks
like:

void menu(name)
{

cout<<"Welcome, "<<name<<", where would you like to go?"<<endl;
cout<<"Please select a destination:"<<endl;
cout<<"A. Natural History Museum"<<endl;
cout<<"B. French Bistro"<<endl;
cout<<"C. Art Gallerey"<<endl;
cout<<"D. Bookshop"<<endl;
cout<<"E. Concert"<<endl;

}

Earlier I was trying to get the places to be arguments, but that was
not working. I think I partially understand how to do that now. i.e.
instead of

cout<<"A. Natural History Museum"<<endl;

it will read

cout<<"A. "<<placea<<endl;

ok. Give it a try.

Sorry, my questions are:
1. why doesnt getline work, and how can I make it work
and

again you posted an incomplete program. I added the "obvious" stuff
and it worked. Presumably some of theis "obvious" stuff isn't obvious
to you. What book are you using?

2. what does "function-style initializer appears to be a function
definition" mean?

the compiler is confused by whatver presceeds your function
definition. Which I can't see...
 
H

HED

The only reason that I hate functions is b/c I am still learning
them.....

OFC, 99% of my problems had to do with the fact that in my naivety
(sp?) I didnt #include<string>

*bangs head into wall*

Thanks, again for the help.

On another note, how do you put code in a code window on the board?

--thanks
 
G

Guest

Subject: "Basically I hate functions..."

you've barely scratched the surface... :)

Yes, wait till you start getting template errors, the really bad ones
can fill several pages.
 
G

Guest

The only reason that I hate functions is b/c I am still learning
them.....

OFC, 99% of my problems had to do with the fact that in my naivety
(sp?) I didnt #include<string>

*bangs head into wall*

Thanks, again for the help.

On another note, how do you put code in a code window on the board?

This is not a board, this is a newsgroup. Newsgroups do not have code
windows or such things, what they have is text. It is unfortunate that
Google does not make that difference clear when using Google Groups. For
more information about posting please see the FAQ (which contains the
answers to many questions) section 5, www.parashift.com/c++-faq-lite/.
 
S

Shadowman

Erik said:
This is not a board, this is a newsgroup. Newsgroups do not have code
windows or such things, what they have is text. It is unfortunate that
Google does not make that difference clear when using Google Groups.

Sure they do. I just checked -- when you reply to a usenet message in
Google Groups, you're presented with this message:

"The group you are posting to is a Usenet group. Messages posted to this
group will make your email address visible to anyone on the Internet."

And there's even a link attached to the words 'Usenet group' that
provides further explanation!


For
 
G

Guest

Sure they do. I just checked -- when you reply to a usenet message in
Google Groups, you're presented with this message:

"The group you are posting to is a Usenet group. Messages posted to this
group will make your email address visible to anyone on the Internet."

And there's even a link attached to the words 'Usenet group' that
provides further explanation!

Yes, but obviously they do not make the difference clear *enough* since
the OP and others continue to confuse newsgroups with other kinds of forums.
 
M

Michael Bell

In message <[email protected]>
HED said:
Ok still a student who is basically teaching himself.... I am haveing
some touble getting how functions work, but I have figured SOME of it
out. (about 1/10 of 1%) My program has this function in it, and
after it is compiling it is telling me "c:\documents and settings\us
\my documents\visual studio 2005\projects
\assingment1\assingment1\assingment4a.cpp(45) : error C3861:
'getline': identifier not found"
huh? I have used getline before in the same format (I even checked
previous assingments), but I do not understand why it is doing that.
string getname()
{
string username;
cout<<"Please enter your name"<<endl;
getline (cin, username);
return username;
}
My other problem is " error C2448: 'menu' : function-style initializer
appears to be a function definition"
I thought i spoke pretty fluent geek until i started trying to debug
my programs.....
I do not understand what it is telling me. Menu is a void function,
but I am (I think/hope) trying to put a string in it, so it looks
like:
void menu(name)
{
cout<<"Welcome, "<<name<<", where would you like to go?"<<endl;
cout<<"Please select a destination:"<<endl;
cout<<"A. Natural History Museum"<<endl;
cout<<"B. French Bistro"<<endl;
cout<<"C. Art Gallerey"<<endl;
cout<<"D. Bookshop"<<endl;
cout<<"E. Concert"<<endl;


Earlier I was trying to get the places to be arguments, but that was
not working. I think I partially understand how to do that now. i.e.
instead of
cout<<"A. Natural History Museum"<<endl;
it will read
cout<<"A. "<<placea<<endl;

Sorry, my questions are:
1. why doesnt getline work, and how can I make it work
and
2. what does "function-style initializer appears to be a function
definition" mean?
Again, thanks in advance.

Like you, I'm a learner. But unlike you I see the beauty and need for
functions. Just think of them as little utilities like an alarm clock,
you set it up to do something that you want it to do, and it does it
without you having to bother yourself more.

Michael Bell



--
 
J

James Kanze

Yes, but obviously they do not make the difference clear
*enough* since the OP and others continue to confuse
newsgroups with other kinds of forums.

But people were making that mistake long before there was
Google. Both bulletin boards and newsgroups have been around
for a long time, and people were getting them confused 15 years
ago, already.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top