Runtime Edit?

This is a discussion on Runtime Edit? within the C++ Programming forums, part of the General Programming Boards category; Hello If our program is: Code: std::string instruction; cout << "Print out next instruction: " ; cin >> instruction; and ...

  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, 12:11 AM
  2. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 06: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, 04:06 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21