Hello World Program in C++

Explanation of the Code:

  1. C++ Code:
    • The C++ code is a simple “Hello, World!” program that uses the iostream library to print text to the console.
  2. HTML Structure:
    • The C++ code is inserted inside the div with id="editor", which is where the Ace Editor displays it.
  3. JavaScript Initialization:
    • Ace Editor is initialized with ace/theme/cobalt for the editor theme.
    • The mode is set to ace/mode/c_cpp, which enables C++ syntax highlighting.
  4. CSS Styling:
    • The heading and editor container are styled similarly to previous examples to maintain consistency.

This code can be embedded directly into your website to display the C++ program within a code editor. Users can modify the code within the editor, and it will provide proper C++ syntax highlighting.

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h3.question {
            font-family: "Roboto", sans-serif;
            font-size: 24px;
            text-align: center;
            font-weight: 100;
        }

        .editor-container {
            width: 900px;
            height: 540px;
            margin: 20px auto;
            position: relative;
        }

        #editor {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            height: 100%;
            width: 100%;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <h3 class="question">Write a simple C++ program</h3>

    <div class="editor-container">
        <div id="editor">// C++ Program\n#include <iostream>\nusing namespace std;\n\nint main() {\n    cout << "Hello, World!" << endl;\n    return 0;\n}</div>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.5.3/ace.js"></script>
    <script>
        var editor = ace.edit("editor");
        editor.setTheme("ace/theme/cobalt");
        editor.session.setMode("ace/mode/c_cpp");
    </script>
</body>
</html>
HTML

Thanks For Visiting Our Website

Leave a Reply

Your email address will not be published. Required fields are marked *

Resize text
Scroll to Top