C++: cant resolve string --> string[]

Discussion in 'Web Design & Coding' started by dubstar, May 21, 2007.

  1. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    attached: code in cpp file.

    i'm trying to pass "userName" string to different functions for logging errors but i seem to be having trouble. I have tried numerous ways of looking at this problem and tried the last 2 days to solve it by myself. any suggestions are welcome!

    help please! :)

    thanks
     

    Attached Files:

  2. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    You want to use something like this

    Code:
    void barf(std::string & narf)
    {
        std::cout << "Stringy is " << narf << std::endl;
    }
    thereby using a reference to a std::string and calling using something like

    Code:
    int main()
    {
        std::string peep = "Hello there world";
        barf(peep);
    }
    that kind of thing should work. X-Istence is probably better on C++ then I am at the moment I have been doing pure C for the last couple of weeks.
     
  3. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    1>emp_strainer_1.cpp(252) : error C2664: 'sortRecords' : cannot convert parameter 14 from 'std::string' to 'std::string []'

    that's the error message.
     
  4. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    are you actually trying to pass in an array of strings?

    the std::string wholly represents a string unlike a char[]. If you are trying to pass in an array though you need to accept a pointer to the first element of the array and possibly another parameter stating the length of the array unless it can be determined some other way. Character array based strings for example have a '\0' character at the end which can be found so you don't need to pass in the array length.
     
  5. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    I have no clue what you are trying to accomplish, please let me know what you are trying to do.
     
    Last edited: May 22, 2007
  6. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    passing the array userName[1] to all my functions. It is an array of 1 string. I am using a string because I do not want to "return" anything in my function.

    the program keeps thinking it is a regular string and that i am converting it to a array


    nevermind, i took that out of the program. i wasted too much time on it.

    thanks for suggestions.
     
    Last edited: May 23, 2007
  7. albybum

    albybum Penguin Rancher

    Messages:
    280
    Location:
    Elizabethton, TN
    In your prototype for the mainMenu function, you have userName specified as a string and not an array:
    ...double tRate[],int flagReadRecords,string userName...

    But when you try to pass it to the readRecords function, that function prototype is expecting an array.
    ...int menuExit[],int flagReadRecords,string userName[]...