Text FormattingC++ Code in LaTeX

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
arnie
Posts: 1
Joined: Sun May 01, 2011 3:23 pm

C++ Code in LaTeX

Post by arnie »

Hello
How to put the C++ code in Latex? For example this code:

Code: Select all

#include <list>
#include <iostream>

using namespace std;

typedef list<int> LISTINT;

int main(void)
{
    LISTINT listOne;
    LISTINT listAnother;
    LISTINT::iterator i;

    // Add some data
    listOne.push_front (2);
    listOne.push_front (1);
    listOne.push_back (3);
    listAnother.push_front(4);
    listAnother.assign(listOne.begin(), listOne.end());

    for (i = listAnother.begin(); i != listAnother.end(); ++i)
        cout << *i << " ";
    cout << endl;
    listAnother.assign(4, 1);

    for (i = listAnother.begin(); i != listAnother.end(); ++i)
        cout << *i << " ";
    cout << endl;
    listAnother.erase(listAnother.begin());

}
Thanks for all help

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

C++ Code in LaTeX

Post by localghost »

Search the forum for listings or minted. The latter one needs Python installed with »pygmentize«.


Best regards and welcome to the board
Thorsten
Post Reply