Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Indianapolis, Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    String Function in C++.

    Would someone mind giving me an example of one please? (First semester programmer)
    Last edited by Wizzy; 03-26-2003 at 11:59 PM.
    - Wizzy

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    example of what? you want a function of a plain string call? be more specific


    Jason

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Indianapolis, Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well my homework is to keep everything out of the int main() as much as possible. So I tried writing a string that asks you're name, but I am not sure where I am going wrong.


    This is just the beginning of it. :-\


    #include <iostream.h>
    #include <string.h>

    using namespace std;

    int main()
    {
    Get_Name(string); // Get's your name.
    system("Pause");
    return 0;
    }

    String Get_Name(string name); // String to get user's name.
    {
    string name;
    cout << "What is your name?" << endl;
    cin >> name;
    return name;
    }
    - Wizzy

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok...in the int main() you call the method Get_Name(string)

    What you are doing when make this call is you are passing it a string the string used in the Get_Name call so you would want something more like

    #include <iostream.h>
    #include <string.h>

    using namespace std;

    int main()
    {
    Get_Name( ); // Get's your name.
    system("Pause");
    return 0;
    }

    String Get_Name( ); // String to get user's name.
    {
    string name;
    cout << "What is your name? " << endl;
    cin >> name;
    return name;
    }


    does that make sense? Im not sure about the syntax being complete...but it should be alright.


    Jason

  • #5
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Indianapolis, Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Awesome.

    I think I got what you said. Sorta. I'll try this out. Thanks much. You're great. :-D
    - Wizzy

  • #6
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Indianapolis, Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sometimes I think my compilar hates me.

    You wouldn't happen to know why I get syntax errors on my cin and cout statements, would you?
    sytax errors before `>' and `<'
    - Wizzy

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    some compilers don't have the ".h" so try #include <iostream>

    otherwise nope...



    Jason

  • #8
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, figured it out...simple stupid coding error....after the function Get_Name() there is a';' there....get rid of it.


    Jason

  • #9
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Indianapolis, Indiana
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I give up

    I give up.
    *grumbles* Now I get an implict deleration of the Get_Name function, and that system pause function.

    Thanks for your help Jason. Much appriciated.
    - Wizzy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •