-
February 1st, 2004, 07:35 PM
#1
Member
linking text file C++
I have a program that reads some numbers from a table, problem is when its compiled and you run it u need to have not only the executable but also the text in the same folder in order for it to work. I was wondering if there was a way to link the text into the executable. All in one package so that you would only need one file instead of two (exe and txt)
I Speak in frequencies even dogs have trouble hearing
-
February 1st, 2004, 07:43 PM
#2
Why not just store the text as a variable? It is plain text isn't it? You can use the STL string class to do this. Just google STL string.
Cheers,
cgkanchi
-
February 1st, 2004, 07:55 PM
#3
Member
Thats a very good idea. Thanx for your input. BYEEEEEEE
I Speak in frequencies even dogs have trouble hearing
-
February 2nd, 2004, 07:40 PM
#4
Member
Now that I started thinking about linking files into programs, is there a way to link programs I coded into already exixting software??? For example I write a program that everytime u open some specific software runs, or viceversa, when I run my program the other software also runs.
I Speak in frequencies even dogs have trouble hearing
-
February 2nd, 2004, 08:07 PM
#5
To call external commands, you can use the system() function. Remember to include the stdlib.h file first, though. For example:
Note: the commented lines show the ISO standard C++ equivalents (in case you need it for class)
Code:
#include <stdlib.h> //#include <cstdlib>
#include <iostream.h> //#include <iostream>
//using namespace std;
int main(int argc, char *argv[] )
{
if(argc!=2)
cout<<"Syntax: run <command>";
else
system(argv[2]);
return 0;
}
Save this program as run.cpp. Compile and run the program using the command "run notepad". If you're in Windows this should show you a notepad window.
Cheers,
cgkanchi
-
February 2nd, 2004, 08:24 PM
#6
Member
#include <stdlib.h> //#include <cstdlib>
#include <iostream.h> //#include <iostream>
//using namespace std;
int main(int argc, char *argv[] )
{
if(argc!=2)
cout<<"Syntax: run <command>";
else
system(argv[2]);
return 0;
}
--------------------------------------------------------------------------------
Thanx for the help, If im not mistaken ure sending here a command when u run it so what this will do is activate whatever program is put as the second parameter when running the program (argv[2]).
So basically I can also use the system commands to open up other programs while my code runs for example
-------------------------------------------------
int main(int argc, char *argv[] )
{
if(argc!=2)
cout<<"Syntax: run <command>";
else
system(argv[2]);
system(iexplorer.exe); // this would make IE open up when it runs??
return 0;
}
IE will open as long as it is on the same directory as the executable????
I Speak in frequencies even dogs have trouble hearing
-
February 3rd, 2004, 04:19 PM
#7
Junior Member
why would you want to run ie?
-
February 3rd, 2004, 09:29 PM
#8
Q-bel - in your case it wouldn't run, or even compile. First, put "iexplorer.exe" inside of quotes. Second, at least on Windows 2K, iexplorer isn't a program in the path anywhere. Although "explorer" works fine. 
BTW, they don't need to be in the same DIR at least for the MS-DOS commands or programs inside of the WinNT/System32 folder since those are all inside of the PATH variable and thus you don't need to type in the folder path - only program name.
...You could even just have your program be a simpler:
PHP Code:
#include <stdlib.h>
#include <iostream.h>
using namespace std;
int main(void)
{
system("explorer");
return 0;
}
But if just want to run programs, the far simpler approach is to make a short-cut to your desktop.
Fasheezy - I've used similar code to start up multiple instances of Internet Explorer, except I used a *.BAT file. It was pretty simple... Maybe Q-bel wants to do the same thing.
-
February 3rd, 2004, 11:13 PM
#9
Member
Thanx for clearing that up about the directories, about opening up explorer that was just an example. Its just that im working on a research with a teacher I took a materials class with and I have to develop a software.Thing is, I wanted to open up (or maybe link so it would be only one executable) a simple program I developed in VB (just for the looks) from my more extensive C++ code (my strong area so its easier to do the hard parts with it). Thanx for the help guys
I Speak in frequencies even dogs have trouble hearing
-
February 4th, 2004, 03:21 PM
#10
Junior Member
tim_axe: thank you! i just learned something new i never new that inbedded function existed in this langauge. i thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|