Thread: Runtime Edit?

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    67

    Smile Runtime Edit?

    Hello

    If our program is:

    Code:
    std::string instruction;
    cout << "Print out next instruction: " ;
    cin >> instruction;
    and the person inputs

    Code:
    cout << "hello" ;
    into the variable instruction at runtime, is there
    any way to make the program interpret this as actual
    source code and make it edit its own source code?
    In which case it would literally print out "hello" in the next
    line of the console?
    Something like reflective programming?

    Thanks

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    No way in C++. It has to be compiled and linked first etc. You have to write an interpreter for this, but this will probably be too much work for such a task. Reflective programming is not for C++.

    You can test the instruction and then use if-else branches to determine what to do now, which would be the best way.

    Please note that this type of programming is highly unsafe and should not be used in general, except if the implementation is secured.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messages from edit control in MFC
    By VirtualAce in forum Windows Programming
    Replies: 0
    Last Post: 01-08-2006, 01:11 AM
  2. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  3. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  4. edit controls
    By ZerOrDie in forum Windows Programming
    Replies: 11
    Last Post: 04-08-2003, 12:09 PM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM

Tags for this Thread