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

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

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
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.

Forum statistics

Threads
62,013
Messages
673,480
Members
5,607
Latest member
endryshall