PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to read output of source code in another program with C++

 August 18, 2022     c++, output, stdout     No comments   

Issue

I think this is really hard to explain what I want. But, let me try. (I am trying to build a program for scoring student's programming homework)

There are a lot of simple source codes in C++. (Please think there are more than 100 code files)

// C:\homework1\studentA.cpp
int main()
{
    cout << "The answer is 456" << endl;
}

And This is question. As you can see, there are tons of code files and I cannot compile it and check it whether right or wrong one by one. So, I need to make scoring program for convenience.

How can I read the standard output (The answer is 456) in another program? Is there any function for 'compiling source code' and 'save standard output' ?


Solution

I would use a bash script for this instead of C++. Something along the lines of:

g++ $filename
./a.out > student_answer.txt
diff -q student_answer.txt expected_answer.txt

Then, $? would tell you whether the answer was correct.



Answered By - Daniel
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing