linking text file C++
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: linking text file C++

  1. #1
    Member
    Join Date
    Sep 2003
    Posts
    76

    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


  2. #2
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    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
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

  3. #3
    Member
    Join Date
    Sep 2003
    Posts
    76
    Thats a very good idea. Thanx for your input. BYEEEEEEE
    I Speak in frequencies even dogs have trouble hearing


  4. #4
    Member
    Join Date
    Sep 2003
    Posts
    76
    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


  5. #5
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    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
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

  6. #6
    Member
    Join Date
    Sep 2003
    Posts
    76
    #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


  7. #7
    Junior Member
    Join Date
    Feb 2004
    Posts
    11
    why would you want to run ie?

  8. #8
    Senior Member
    Join Date
    Oct 2001
    Posts
    786
    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.

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

  9. #9
    Member
    Join Date
    Sep 2003
    Posts
    76
    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


  10. #10
    Junior Member
    Join Date
    Feb 2004
    Posts
    11
    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
  •