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

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

Geffy

OSNN Veteran Addict
#2
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
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
#4
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.
 
#6
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
#7
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 posts

Latest profile posts

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 https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,970
Messages
673,297
Members
89,017
Latest member
Poseeut