Thread: File input/output questions

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    6

    File input/output questions

    I know that I can save and read .txt file using c++. But I'm wondering, can I run a sourcecode written in a .txt file(or whatever file it is) like an another function but in another file. Picking up what am I pointing?
    Really appreciate for responds and if it exist, can someone provide me a sample sourcecode/program for it?
    Thanks alot!

  2. #2
    Guest
    Guest
    I'm not aware of any way to compile source code on the fly and call it from within your current program (rather than as a separate executable). Why would you want to do that anyway? Just tinkering?

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    6
    Oh well. Thanks men! Appreciate alot. But I'm still hoping that running a sourcecode in a .txt file is a thing is c++, hoping. Haha
    The reason? I'm thinking a unique way to make a simple database using c++.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by forpetesake568
    But I'm wondering, can I run a sourcecode written in a .txt file(or whatever file it is) like an another function but in another file. Picking up what am I pointing?
    Really appreciate for responds and if it exist, can someone provide me a sample sourcecode/program for it?
    This certainly can be done: just as a compiler can be written in C++, an interpreter for a programming language can be written in C++. I believe that there are existing interpreters for (possibly some subset or earlier version of) C++ itself, but I cannot recommend any as I have never tried one.

    Quote Originally Posted by forpetesake568
    I'm thinking a unique way to make a simple database using c++.
    You might want to investigate existing database software. For example, the source code for SQLite is freely available, though it is in C rather than C++, but the same can certainly be done in C++. The documentation on the SQLite Virtual Machine begins with this introduction:
    In order to execute an SQL statement, the SQLite library first parses the SQL, analyzes the statement, then generates a short program to execute the statement. The program is generated for a "virtual machine" implemented by the SQLite library. That virtual machine is sometimes called the "VDBE" or "Virtual DataBase Engine".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-01-2014, 08:14 AM
  2. Replies: 2
    Last Post: 08-30-2014, 11:07 PM
  3. Naming an output file based on an input file name
    By mbxs3 in forum C Programming
    Replies: 4
    Last Post: 09-07-2013, 06:30 PM
  4. file input/output
    By joker_tony in forum C Programming
    Replies: 3
    Last Post: 08-03-2009, 05:00 PM
  5. file input/output
    By Bigbio2002 in forum C Programming
    Replies: 3
    Last Post: 10-29-2003, 01:45 AM