ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok, im getting the following compile errors my code is below also :-
gameserverpro14.cpp: In function `int main()':
gameserverpro14.cpp:82: error: invalid operands of types `char[256]' and `const
char[17]' to binary `operator+'
gameserverpro14.cpp:83: error: syntax error before `,' token
Code:
cout << "Please select game you wish to run: ";
cin.get();
system(s3+" > system_errors");
cin.getline(s3,, 100); //input goes in
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int i=0;
char s1[30],s2[40],s3[90],s4[100]; // set char size for input
ofstream outfile("games.db", ios::app);
string whole,p1,p2;
ifstream infile;
// Start Main Menu
char choice='\0';//NULL;
bool finished=false;
while (finished != true)
{
cout<<"MAIN MENU\n";
cout<<"1. AddGame\n";
cout<<"2. Options\n";
cout<<"3. RunGame\n";
cout<<"4. Exit\n";
cout << "Please enter your choice: ";
cin>>choice;
cout<<"\n\n";
// Start function for submenu
switch(choice)
{
case '1': cout << "1. Add Game To DB\n";
cout << "2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1')
{
cout << "\n\nPlease enter full-path to game start file: ";
cin.get();
cin.getline (s1, 30); // Input goes in$
outfile << s1 << ":"; // add : after eachpath
cout << "\n\nPlease enter game name: ";
cin.getline (s2, 40);
outfile << s2 << "\n";
if (outfile.is_open())
{
outfile.close();
}
}
/* Just break if choice != 1 */
break;
case '2': cout<<"Options\n";
cout<<"1. Edit Game Config\n";
cout<<"2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice=='1')
{
cout << "Please enter full path to config file to edit: "; // ask user for path to config file
cin.get();
cin.getline (s3, 256); // input goes in
string cmd = string("pico ") + string(s2);
system(cmd.data()); // open up pico to edit config
}
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '3': cout<<"Run Game";
i=0;
infile.open ("games.db", ios::in);
while(getline(infile,whole)){
i++;
p2=whole.substr(whole.find(':')+1,whole.length());
cout << i << ". " << p2 << endl;
}
cout << "Please select game you wish to run: ";
cin.get();
cin.getline(s3, 100);
system ( (string(s3)+" > system_errors").c_str() );
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '4': //Finished so set finished 'true' to break out of loop
finished=true;
cout<<"Exiting....\n";
break;
default: //If choice !=1/2/3 then do what it says here
break;
// end functions
}
choice='\0'; //NULL
}
return 1;
}
ok so i need to search my file for entry #, and find the command to run or load it all in memory and use std::map or something.
The problem is i have no idea how todo either of them, as i aint even done anything with std::map yet.
thankyou
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int i=0;
char s1[30],s2[40],s3[90],s4[100]; // set char size for input
ofstream outfile("games.db", ios::app);
string whole,p1,p2;
ifstream infile;
// Start Main Menu
char choice='\0';//NULL;
bool finished=false;
while (finished != true)
{
cout<<"MAIN MENU\n";
cout<<"1. AddGame\n";
cout<<"2. Options\n";
cout<<"3. RunGame\n";
cout<<"4. Exit\n";
cout << "Please enter your choice: ";
cin>>choice;
cout<<"\n\n";
// Start function for submenu
switch(choice)
{
case '1': cout << "1. Add Game To DB\n";
cout << "2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice == '1')
{
cout << "\n\nPlease enter full-path to game start file: ";
cin.get();
cin.getline (s1, 30); // Input goes in$
outfile << s1 << ":"; // add : after eachpath
cout << "\n\nPlease enter game name: ";
cin.getline (s2, 40);
outfile << s2 << "\n";
if (outfile.is_open())
{
outfile.close();
}
}
/* Just break if choice != 1 */
break;
case '2': cout<<"Options\n";
cout<<"1. Edit Game Config\n";
cout<<"2. Go back\n";
cout << "Please enter your choice: ";
cin>>choice;
if(choice=='1')
{
cout << "Please enter full path to config file to edit: "; // ask user for path to config file
cin.get();
cin.getline (s3, 256); // input goes in
string cmd = string("pico ") + string(s2);
system(cmd.data()); // open up pico to edit config
}
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '3': cout<<"Run Game";
i=0;
infile.open ("games.db", ios::in);
while(getline(infile,whole)){
i++;
p2=whole.substr(whole.find(':')+1,whole.length());
cout << i << ". " << p2 << endl;
}
cout << "Please select game you wish to run: ";
cin.get();
cin.getline(s3, 100);
system ( (string(s3)+" > system_errors").c_str() );
// Here we would check 'choice' and probably move to another functi$
cout<<"\n\n";
break;
case '4': //Finished so set finished 'true' to break out of loop
finished=true;
cout<<"Exiting....\n";
break;
default: //If choice !=1/2/3 then do what it says here
break;
// end functions
}
choice='\0'; //NULL
}
return 1;
}
i tried changing the code to what is below but that dont seem to fix it, that does, is it because iv got it the wrong way round and it should be i-- and not i++ ?
:-
un Game1. Battlefield 2
Please select game you wish to run:
1
sh: line 1: 1: command not found
My code :-
Code:
case '3': cout<<"Run Game";
i=0;
infile.open ("games.db", ios::in);
while(getline(infile,whole)){
i++;
p2=whole.substr(whole.find(':')+1,whole.length());
cout << i << ". " << p2 << endl;
}
cout << "Please select game you wish to run: " << endl;
cin.get();
cin.getline(s3, 100);
i=0;
infile.open ("games.db", ios::in);
while(getline(infile,whole)){
i++;
p1=whole.substr(whole.find(':')-1,whole.length());
cout << i << ". " << p1 << endl;
}
system ( (string(s3)+" > system_errors").c_str() );
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.