From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: evaluate cpp snippet in org babel with default includes and customized entry point Date: Sat, 16 Sep 2017 10:46:29 +0200 Message-ID: <59BCE4E5.2080707@free.fr> References: <877ewz9j4x.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dt8kE-0006WB-P7 for emacs-orgmode@gnu.org; Sat, 16 Sep 2017 04:46:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dt8kB-0004ut-Hn for emacs-orgmode@gnu.org; Sat, 16 Sep 2017 04:46:34 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:5358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dt8kB-0004uA-Bp for emacs-orgmode@gnu.org; Sat, 16 Sep 2017 04:46:31 -0400 Received: from [IPv6:2a01:e35:2e21:def0:997a:f49e:9a7c:91e1] (unknown [IPv6:2a01:e35:2e21:def0:997a:f49e:9a7c:91e1]) by smtp1-g21.free.fr (Postfix) with ESMTP id DFC12B002B5 for ; Sat, 16 Sep 2017 10:46:29 +0200 (CEST) In-Reply-To: <877ewz9j4x.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Another starting point without hard-coding inputs: #+name: NUMS | 2 | | 7 | | 11 | | 15 | #+BEGIN_SRC C++ :flags -std=3Dc++11 :var target=3D9 :var inputnums=3DNUMS #include #include using namespace std; class Solution { public: vector twoSum(vector& nums, int target) { vector result; result.push_back(0); result.push_back(1); return result; } }; int main() { Solution solution; vector nums; for (int* in : inputnums) nums.push_back(*in); for (int x : solution.twoSum(nums,target)) cout< > Hi > > I'd like to write a blog about leetcode solutions in c++. How can I=20 > evaluate those c++ code snippet using org babel? > > > 1 Array > > > 1.1 Two Sum > > Given an array of integers, return indices of the two numbers such=20 > that they add up to a specific target. > > You may assume that each input would have exactly one solution, and=20 > you may not use the same element twice. > > Example: > Given nums =3D [2, 7, 11, 15], target =3D 9, > > Because nums[0] + nums[1] =3D 2 + 7 =3D 9, > return [0, 1]. > > |class Solution { > public: > vector twoSum(vector&nums,int target) { > > } > }; > | > > I need to add default headers and pass arguments to the entry class. > > =96 > Amos Bird > amosbird@gmail.com >