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

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
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
 

Attachments

  • Emp_Strainer_1.zip
    6.3 KB · Views: 121

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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.
 

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
1>emp_strainer_1.cpp(252) : error C2664: 'sortRecords' : cannot convert parameter 14 from 'std::string' to 'std::string []'

that's the error message.
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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.
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
I have no clue what you are trying to accomplish, please let me know what you are trying to do.
 
Last edited:

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
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:

albybum

Penguin Rancher
Joined
9 Feb 2002
Messages
281
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[]...
 

Members online

No members online now.

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR