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

Discussion in 'C++' started by HED, Oct 11, 2007.

  1. HED

    HED 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;
    }

    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.
    HED, Oct 11, 2007
    #1
    1. Advertising

  2. On 2007-10-11 11:47, HED wrote:
    > 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)

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 11, 2007
    #2
    1. Advertising

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


    On 11 Oct, 10:47, HED <> wrote:

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


    --
    Nick Keighley
    Nick Keighley, Oct 11, 2007
    #3
  4. HED

    HED 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?

    --thanks
    HED, Oct 11, 2007
    #4
  5. On 2007-10-11 12:15, Nick Keighley wrote:
    > Subject: "Basically I hate functions..."
    >> I thought i spoke pretty fluent geek until i started trying to debug
    >> my programs.....

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


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

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 11, 2007
    #5
  6. On 2007-10-11 12:24, HED wrote:
    > 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/.

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 11, 2007
    #6
  7. HED

    Shadowman Guest

    Erik Wikström wrote:
    > On 2007-10-11 12:24, HED wrote:
    >> 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.


    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
    > more information about posting please see the FAQ (which contains the
    > answers to many questions) section 5, www.parashift.com/c -faq-lite/.
    >



    --
    SM
    rot13 for email
    Shadowman, Oct 11, 2007
    #7
  8. On 2007-10-11 15:55, Shadowman wrote:
    > Erik Wikström wrote:
    >> On 2007-10-11 12:24, HED wrote:
    >>> 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.

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

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 11, 2007
    #8
  9. HED

    Michael Bell Guest

    In message <>
    HED <> wrote:

    > 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



    --
    Michael Bell, Oct 11, 2007
    #9
  10. HED

    Default User Guest

    HED wrote:

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


    This is exactly why you should post a complete, minimal program rather
    than snippets. See the FAQs (particularly 5.8):

    <http://www.parashift.com/c++-faq-lite/how-to-post.html>





    Brian
    Default User, Oct 11, 2007
    #10
  11. HED

    James Kanze Guest

    On Oct 11, 4:20 pm, Erik Wikström <> wrote:
    > On 2007-10-11 15:55, Shadowman wrote:
    > > Erik Wikström wrote:


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


    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.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Oct 11, 2007
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish

    you know what I really hate?

    Andy Fish, Jul 16, 2004, in forum: Java
    Replies:
    2
    Views:
    355
    Peter Kirk
    Jul 21, 2004
  2. Claude
    Replies:
    0
    Views:
    341
    Claude
    Mar 7, 2004
  3. Jack Saalweachter

    God, software patents, I hate you, die.

    Jack Saalweachter, Oct 25, 2005, in forum: C++
    Replies:
    1
    Views:
    290
    Jack Saalweachter
    Oct 25, 2005
  4. Weng Tianxiang
    Replies:
    2
    Views:
    531
    Eric Smith
    Feb 16, 2010
  5. Giles Bowkett

    def if ; end - basically impossible?

    Giles Bowkett, Dec 28, 2007, in forum: Ruby
    Replies:
    10
    Views:
    218
    Paul Brannan
    Jan 1, 2008
Loading...

Share This Page