Defining strings

I hope this can be done, here is an example of what I'm doing:

1
2
3
4
5
6
     cout << " -------------\n";
     cout << "|   1   2   3 |\n|             |\n";
     cout << "| A $          |\n|             |\n| B           |\n|             |\n| C           |\n|             |\n";
     cout << " -------------\n";
     cout << "$ = You\n";
     cout << "* = Computer\n";


Now I want it to check if some thing has heppend further down the code, I can do that, but I want to "#define $ *" if some thing has happend further down the code, so all of the $ in this will become * so if I'm talking about the computer it will display * and not $. Is this possible?
Last edited on
Do you wish to change * to $ at compile or run-time?

If at compile-time you can do a #define $ * no problem.

At run-time probabley a string replace is what you need.
I need it to change after some thing happens, and I can make that thing happen no problem, I just need a way to change all of the $ to * it will save me a lot of time.
1
2
3
4
5
string dollar = "You";
string star = "Computer";
...
cout << "$ = " << dollar << "\n";
cout << "* = " << star << "\n";

Please come up with better names than 'dollar' and 'star'.

Hope this helps.
Do you wish to change * to $ at compile or run-time?
run-time, after I reach a point in the program, like once some thing happens, I can make the thing happen but I don't know how to change the $ to *
If you meant within the string, then I recommend find(). Or create a string that you use in place of * and $ for all your other strings.
http://cplusplus.com/reference/string/string/find/
http://cplusplus.com/reference/string/string/replace/

-Albatross
Last edited on
If you mean parameterizing a function that draws your game board so that it can display an asterisk or a dollar sign, do exactly that--make a function and pass it an argument.

If you mean, overwriting the text in-place on the console, consider using ncurses.
Topic archived. No new replies allowed.