PDA

Click to See Complete Forum and Search --> : linking text file C++


Q-bel
February 1st, 2004, 07:35 PM
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)

cgkanchi
February 1st, 2004, 07:43 PM
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

Q-bel
February 1st, 2004, 07:55 PM
Thats a very good idea. Thanx for your input. BYEEEEEEE

Q-bel
February 2nd, 2004, 07:40 PM
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.

cgkanchi
February 2nd, 2004, 08:07 PM
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)

#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

Q-bel
February 2nd, 2004, 08:24 PM
#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????

Fasheezy
February 3rd, 2004, 04:19 PM
why would you want to run ie?

Tim_axe
February 3rd, 2004, 09:29 PM
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:


#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.


explorer http://website_1
explorer http://website_2
explorer http://website_3
explorer http://website_4

Q-bel
February 3rd, 2004, 11:13 PM
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

Fasheezy
February 4th, 2004, 03:21 PM
tim_axe: thank you! i just learned something new :) i never new that inbedded function existed in this langauge. i thank you

AxessTerminated
February 6th, 2004, 12:26 AM
Hey, I was just wondering what you guys did to put in those horizontal line breaks.
I always see the word "code:" then a line break below it, some code, and then another line break. Is this done in with options on the Add Post interface?

Negative
February 10th, 2004, 03:38 AM
It's called Site Code, Axess.
You can use Site Code by using the "[" and "]" symbols.

Example:

This is done by adding the [code ]-tag. [/code ] finishes the code. Without the spaces ;)


Same goes for "quote". This is done by starting your quote with "[ quote]" and ending it with "[/quote ]".

Here's (http://www.antionline.com/misc.php?action=bbcode#buttons) the complete explanation.

slayerchange
February 10th, 2004, 12:15 PM
Instead of system() function , first try to search desired *.exe. If you find it, then try exec() command.