write int followed by char

closed account (Dy0fSL3A)
Hey, I am trying to write a string called pathSegment using an int(pathNumber) followed by a char(pathLetter)
For example, if pathNumber is 12 and pathLetter is e, pathSegment is 12e.
However, I am not sure how to make this happen.
This is what i have right now
string PathSegment(int pathNumber, char pathLetter);


int main()
{

cout << PathSegment(12,e) << endl;
}

string PathSegment(int pathNumber, char pathLetter)
{
if(pathNumber >= 0 && pathNumber <= 99)
{
if (pathLetter == 'e' || pathLetter == 'w' || pathLetter == 's' || pathLetter == 'n' || pathLetter == 'E' || pathLetter == 'S'|| pathLetter == 'N' || pathLetter == 'W')
{
return pathNumber << pathLetter;
}
}
}

I also have the qualifications that pathNumber is two digits and pathLetter is a cardinal direction, lowercase or uppercase. Sorry I am relatively new to C++ and this is pretty complicated for me so I may have made one(or more) simple mistakes.
When I call pathSegment in my main function, I get a weird symbol instead of 12e
Last edited on
That's because pathNumber << pathLetter does a bitwise left shift on pathNumber the number of times pathLetter is equal to as an integer. It sounds kind of like you want to use a stringstream for pathSegment here, at which point you can put those values into it like cout.
Topic archived. No new replies allowed.