|
 |
|
 |
11-03-2004, 08:41 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
main menu
I have done some work while in college and it is all saved, what I want to do is create a main menu program that will probably be driven off a case statment but anywho I was wondering if there was anyway I could attatch external .cpp files to the main menu.
Example ...
* If the user enters 1 then 1.cpp is loaded (1.cpp being a program I have already created)
* If the user enters 2 then 2.cpp is loaded (2.cpp being a program I have already created)
... and so on for however many programs I have saved, is this possible?
|
|
|
11-03-2004, 09:32 AM
|
#2 (permalink)
|
|
Registered User
Join Date: Sep 2004
Posts: 6
|
You mean you want to call other programs from inside your program? This can be done using the spawnxx functions.
|
|
|
11-03-2004, 10:21 AM
|
#3 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
Yes I want to call other .cpp files from my mainmenu.cpp
|
|
|
11-04-2004, 06:59 AM
|
#4 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
?
|
|
|
11-04-2004, 07:31 AM
|
#5 (permalink)
|
|
Registered User
Join Date: Sep 2004
Posts: 6
|
To call other programs, or to open .cpp files? These are 2 different kind of things, since a .cpp file is a text file, not a program...
Last edited by frrossk; 11-04-2004 at 07:34 AM.
Reason: bad spelling
|
|
|
11-04-2004, 11:48 AM
|
#6 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
Ok maybe I can make myself a little more clear, what I have right now is 12 independent programs that are due at the end of the semester. Instead of turning in a folder to my teacher where he has to click on each different .cpp to open it I would like to create another .cpp file and it would act as the main menu from here he could select lab 1 through lab 12 once he enters which lab he wants to see that .cpp file is then loaded.
Example
Which lab would you like to view?
1. Lab 1
2. Lab 2
3. Lab 3
4. Lab 4
(if the user enter the number 4 then the case statment loads 4.cpp)
.... is this posible or is there another way to do all of this?
|
|
|
11-04-2004, 09:00 PM
|
#7 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
What means "loaded"? Do you just want to show the corresponding C++ code in console?
__________________
|
|
|
11-05-2004, 05:15 AM
|
#8 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
Yeah I just want to have the code shown, loaded was just a figure of speach.
|
|
|
11-05-2004, 06:14 AM
|
#9 (permalink)
|
|
Registered User
Join Date: Sep 2004
Posts: 6
|
So, you have only to open the file (Lab x), then read the lines in that file and display them on the screen. A kind of:
Code:
fopen (Lab x);
while (!feof)
{
gets (file, string);
printf (string);
}
(just an idea)
Last edited by frrossk; 11-05-2004 at 06:15 AM.
Reason: bad spelling
|
|
|
11-06-2004, 02:27 AM
|
#10 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Code:
#include <iostream>
#include <string>
#include <fstream>
using std::cin;
using std::cout;
using std::string;
using std::ifstream;
using std::endl;
using std::getline;
int main(int argc, char *argv[])
{
ifstream theFile;
string theFileName;
while(1)
{
cout<<"\t\t\tEnter the option:"<<endl;
cout<<"\t\t\t1 = Lab 1.cpp"<<endl;
cout<<"\t\t\t2 = Lab 2.cpp"<<endl;
cout<<"\t\t\t3 = Lab 3.cpp"<<endl;
cout<<"\t\t\t4 = Lab 4.cpp"<<endl;
cout<<"\t\t\tCTRL+Z/D = quit."<<endl;
getline(cin, theFileName);
//User wants to quit?
if( cin.eof() )
{
//User wants to quit. Get out of the while-loop.
break;
}
//Assuming files are named like: Lab_1.cpp, Lab_2.cpp etcetera.
theFileName.insert(0, "Lab_");
theFileName += ".cpp";
theFile.open( theFileName.c_str() );
if( !theFile )
{
cout<<endl<<"ERROR!"<<endl;
cout<<"Reason: could not open the file."<<endl;
cout<<"Make sure your entry is valid."<<endl<<endl;
theFile.close();
theFile.clear();
}
if( theFile.is_open() )
{
cout<<"*** File starts below ***"<<endl<<endl;
cout<<theFile.rdbuf();
cout<<endl<<"*** File ended ***"<<endl<<endl;
theFile.close();
}
}
return 0;
}
__________________
|
|
|
11-08-2004, 09:03 AM
|
#11 (permalink)
|
|
Registered User
Join Date: Sep 2004
Location: Lancaster, Pa
Posts: 24
|
I'll mess around with it Val, thanx and I'll get back to you.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 12:56 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|