Hi, I have tried to do it as you said and i get the following errors :-
Quote:
------------------------- Code:
r.c_str(); // convert string r to const char |
There seams to be some confusion here.
Code:
r.c_str(); // convert string r to const char Anywhere you do something like this: std::cout << "atoi(r) = " << atoi(r) << endl; Needs to be changed to this: std::cout << "atoi(r.c_str()) = " << atoi(r.c_str()) << endl; |
Quote:
Code:
const char *temp = str1.c_str(); |
Hi,
Thankyou for your reply. I am still having problems converting std::string to const char the errors i get are below followed with my code. Quote:
------------------------------------------------ Code:
r.c_str(); // return a c string version of r |
Ok, lets go over this one more time....
If you get an error that says this: error: cannot convert `std::string' to `const char*' then it means that somewhere in your code (AKA the line in the error message) you are passing in a std::string instead of a c_string (or const char *). Lets break down the first one. gamepro11.cpp:160: error: cannot convert `std::string' to `const char*' for argument `1' to `int chdir(const char*)' On line 160 we have the following statement: chdir(p); // enter directory of path Now, the error says that argument 1 of int chdir(const char*) is the problem. As we see here, p is a std::string. chdir wants a const char *. As a result this needs to be changed to chdir(p.c_str());. As far as the cross-initialization goes... you don't need the Code:
const char *rungame = r.c_str(); |
As far as the last type of error goes (error: jump to case label)....
I believe this is the problem: Code:
// Here we would check 'choice' and probably move to another functi$ |
Hi,
Thankyou for your reply i fixed the code by doing the following, and it now compiles. Thankyou all for your help :- Code:
r.c_str(); // return a c string version of r |
Hi, how do i solve my problems, now i have got it to compile please?
1. I have to press enter for program to load 2. Dont ask for game name when adding game to games.db 3. When adding games to the games.db i have to press enter after each line 4. Its storing wrong information into games.db like Please enter full-path to game:;.Please enter name of startup file: e.g ./start$ 5. When executing game it does :- Run Game1. ;.Please enter name of startup file: e.g ./start.sh:Please enter name of game: Please select game you wish to run: atoi(r.c_str()) = 0 i = 2 Changing directory to <Please enter full-path to game:> Executing system(Please enter name of startup file: e.g ./start.sh) sh: Please: command not found MAIN MENU 1. AddGame 2. Options 3. RunGame 4. Exit Please enter your choice: My code :- --------------------------------------------------- Code:
#include <iostream> |
I'll try not to rewrite you code for you, but I think highlighting the trouble areas should help. I've added line numbers to help explain.
Code:
1 #include <iostream> Code:
using namespace std; Lines 17-26; Lines 71, 77, 82, 102, 130, 159: Because each use of cout here is to print a static string to the screen, the use of string objects is unnecessary. It will cause a (very minor) increase in memory and processor usage, but more importantly in this case, I get the impression that you've confused yourself, and it makes the code more difficult for others to read. Because you don't need to modify what the prompts are saying, I'd suggest that you get rid of the strings and replace the cout lines with (for example): Code:
cout << "Please enter full-path to game:" << endl; This is the reason that you have needed to press enter after starting the program. Lines 73, 79, 104: Duplicate getlines; these are the reason that you have needed to press enter again after entering something. Lines 74, 80, 83, 106, 147, 151, 160, 162: In each of these lines, you've used your prompt string variables, where I think you meant to use line, whole, or some other string. <edit> Reading your code again, it looks as though you might be thinking that this: Code:
std::cout << r << endl; </edit> Lines 143-145: These lines are unnecessary, because you don't use the pointers that are returned. If you did need to use something.c_str() a few times, then theoretically you could gain some speed by using pointers like this, rather than calling the function a number of times. You would gain very little speed though, and I'm not sure that the pointer returned by c_str() is guaranteed to be valid after the string changes. I hope that helps you a bit. :) ~sind |
Thankyou very much LINUX QUESTIONS and Sind And Everyone Else! My program now works they way it should and works quite well :D .
Anyone want to design a gui for it please? Thankyou |
Hi,
Ok i have ran into to snags in the program what are :- 1. If a user wishes to use parameters on the same line as ./start.sh -whatever -so -so here he/she cannot do that as it tends to have a char limit? 2.After running a program/game the program does not return to the menu like :- Run Game1. bfsmd 2. Bf1942 Please select game you wish to run: 2 atoi(r.c_str()) = 2 i = 2 i = 3 Changing directory to </home/twirl/bf1942/> Executing system(./start.sh) ./start.sh: using dynamically linked binary Please help so i can fix this. Thankyou twirl |
Sounds like you'd better post the code again. :D Either that or host it somewhere and post a link.
Quote:
Once again, I haven't used it but I remember reading that Glade (which uses GTK, IIRC) can be a quick-start for GUIs. ~sind |
Hi,
Thankyou for your reply, here is my latest code with the problems above. Also how would i add a way so the user can delete what is stored in games.db? 2. Is it possible to add a way of showing the user what servers/games are running? Thankyou twirl My code :- Code:
#include <iostream> |
All times are GMT -5. The time now is 04:37 PM. |