Discuss Scratch

amiramine
Scratcher
42 posts

The C++ code language topic

1 What is C++?


C++ is a compiled programming language allowing programming under multiple paradigms, including procedural programming, object-oriented programming, and generic programming. And i want to the scratch team add this language to scratch

Why i want to add the C++ code language ?

1 C++ is used to create computer programs, and is one of the most used language in game development.
2 the C++ language can help old scratchers to make games easly
3 the C++ ls a famous code language and it will be nice to update scratch

How can we use C++ language?

1 Search in google or youtube for tutorials to use the C++ code language.
2 make more games in other apps like godot and python to use the C++ language in scratch .

see this https://openclassrooms.com/fr/courses/1894236-apprenez-a-programmer-en-c

#include <iostream>

int main()
{
using std::cout;
// std::cout est disponible sans utilisation de std::
cout << “Hello, new world!” << std::endl; // mais pas std::endl (endline)
}

void foo()
{
// std::cout n'est plus disponible sans utilisation de std::
std::cout << “Hello, new world!” << std::endl;
}
Thats all for the day, thanks for reading my topic .

Last edited by amiramine (Aug. 3, 2024 22:52:35)

BiggestBrainBoy
Scratcher
35 posts

The C++ code language topic

HI! my parents are computer programmers and they use C++!
amiramine
Scratcher
42 posts

The C++ code language topic

BiggestBrainBoy wrote:

HI! my parents are computer programmers and they use C++!

Good
BigNate469
Scratcher
1000+ posts

The C++ code language topic

Kind of amazing how a programming language created in 1989 is still relevant and popular today…

Then again, this shouldn't be all that surprising considering that C is ten years older and still being used (notably almost all of the Linux kernel is written in C). You can even still run BASIC and FORTRAN on modern-day computers, dispite being some of the oldest programming languages in the world.

TheTeoScratcher
Scratcher
3 posts

The C++ code language topic

#include [iostream v] :: events
using namespace [std v]; :: sensing
[int v] main\() \{ {
cout \<\< ["Hello, World!"]; :: looks
[int v] [num1]; :: variables
cin >> (num1); :: sensing
if \(<(num1) [== v] (5)::operators>> \) {
cout \<\< ["num1 is 5"]; :: looks
} \} ::control
for \([int v] [i]; (i) [\<= v] (5);(i)[++ v];\) {
cout \<\< (["i is "] \<\< ((i) \<\< [endl v]::operators)::operators); :: looks
}::control
}}:: events

heres my attemps to make c++ scratch-like
oti_mr_Chicken
Scratcher
100+ posts

The C++ code language topic

Yeah I wrote my DPCM decoder in C++ (will make a lossless 7-bit PCM)
#include <iostream>
#include <sndfile.hh>
#include <algorithm>
#include <fstream>
using namespace std;
int decode(u_int8_t * array,size_t ssize, string filename);
int main(int argc, char *argv[])
{
    if (argc < 3) {
        cerr << "No output specified" << endl << "Where will it go then?" << endl;
        return 1;
    }
    if (argc < 2) {
        cerr << "No input specified" << endl;
        return 1;
    }
    ifstream Input(argv[1], ios::binary | ios::ate);
    if(!Input) {
        cerr << "Failed to open data" << endl;
        return -1;
    }
    streamsize size = Input.tellg();
    if (size < 0) {
        cerr << "Failed to find file size" << endl;
        return -1;
    }
    char buffer[(size_t)size];
    cout << (size_t)size << endl;
    Input.seekg(0,ios::beg);
    if (!Input.read(buffer,size)) {
        cerr << "nooo" << endl;
        return -1;
    }
    return  decode((u_int8_t*)buffer,(size_t)size,argv[2]);
}
int8_t Fetch(u_int8_t toDecode, bool decodeSecond)
{
    int8_t output = 0;
    if (decodeSecond)
    {
        output = int((toDecode & 0xf0) >> 4) - 8;
    } else
    {
        output = int(toDecode & 0b00001111) - 8;
    }
    return output;
}
int decode(u_int8_t * array,size_t ssize, string filename)
{
    int16_t currentSample = 0;
    size_t arraySize = ssize;
    int16_t output[arraySize * 2] = {0};
    cout << " size " << arraySize * 2 << endl;
    int8_t currentError = 0;
    for (u_int32_t i = 0; i < arraySize * 2; i++) {
        currentError = Fetch(array[(int)(i /2)],(int)(i % 2));
        currentSample += currentError;
        output[i] = currentSample;
        cout << "Sample " << i <<" Error " << (int)currentError << " Step " << currentSample << " Decodery \n";
    }
    int maxval = *std::max_element(output, output + sizeof(output) / sizeof(output[0]));
    int minval = *std::min_element(output, output + sizeof(output) / sizeof(output[0]));
    int toNorm = 32767 / max(maxval,-minval);
    cout << toNorm <<" "<< maxval << endl;
    for (int t = 0;t < sizeof(output) / sizeof(output[0]); t++){
        output[t] *= toNorm;
    }
    const int channels = 1;
    const int sampleRate = 8000;
    const int format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
    const char* outfilename = filename.c_str();
    SndfileHandle outfile(outfilename, SFM_WRITE, format, channels, sampleRate);
    if (!outfile) {
        cout << "Failed to open wave";
        return 1;
    }
    outfile.write(output,sizeof(output) / sizeof(output[0]));
    cout << "Output sucsessfly packaged as " << filename << endl ;
    return 0;
}

Last edited by oti_mr_Chicken (Jan. 20, 2026 19:04:09)

oti_mr_Chicken
Scratcher
100+ posts

The C++ code language topic

CodeComet6161 wrote:

And no one has mentioned the duplicate after 1 year
According to ma007rio on the forum you suggested.

ma007rio wrote:

Since this is an *awfully* old topic:

just go here

https://scratch.mit.edu/discuss/topic/773800/
It's an awfully old topic.
This is more like a fresh start to me because, I discovered this forum first before the forum you suggested.
dem_bot
Scratcher
500+ posts

The C++ code language topic

I was wondering, is there any way for me to learn C++ without the whole, hello world, hello world but with an input, hello world but now ur input changes the text colour etc. ?
TechNerd64
Scratcher
500+ posts

The C++ code language topic

C++ is also quite prominent among the DIY electronics community for its extensive use in microcontrollers like the Arduino platform
TeoProotTest
Scratcher
34 posts

The C++ code language topic

TechNerd64 wrote:

C++ is also quite prominent among the DIY electronics community for its extensive use in microcontrollers like the Arduino platform
I know C#. Is C++ a good stepping stone from there?
MineTurte
Scratcher
1000+ posts

The C++ code language topic

TeoProotTest wrote:

TechNerd64 wrote:

C++ is also quite prominent among the DIY electronics community for its extensive use in microcontrollers like the Arduino platform
I know C#. Is C++ a good stepping stone from there?
I'd say that if anything Java is closer to C# (I mean C# is Microsoft's version of Java but like… yeah) but C++ is a route you can take if you'd like. Considering you've learned a fairly “high-level” programming language it's better to go to another “high-level” language (C++ is considered intermediate).

yes I know this post is 13 days old, that isn't that old.

Last edited by MineTurte (Jan. 28, 2026 20:57:28)

oti_mr_Chicken
Scratcher
100+ posts

The C++ code language topic

Pretty much, I pretty like code::blocks.
pongus-
Scratcher
49 posts

The C++ code language topic

What's the difference between C, C++, and C#?
gem1001
Scratcher
1000+ posts

The C++ code language topic

pongus- wrote:

What's the difference between C, C++, and C#?
C is the original language from 1972:
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
C++ is an extended version from 1985:
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!";
  return 0;
}
C++ adds some new features; for example, there is a ‘string’ type, whereas in C you have to use an array of ‘char’s.

Finally, C♯ is an object oriented language loosely based on C by Microsoft from 2000:
using System;
namespace Hello {
  class Hello {
     static void Main(string[] args) {
        Console.WriteLine("Hello, World!");
     }
  }
}
If you think this looks more like Java than C, you are not alone.

Last edited by gem1001 (March 5, 2026 08:42:37)

ispretty
Scratcher
500+ posts

The C++ code language topic

gem1001 wrote:

-snip-
C++ is an extended version from 1985:
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!";
  return 0;
}
Whilst forcing you to manually pipe to cout instead of having a function like printf() seems like an abridgement rather than an extension, C++ does add new features; for example, there is a ‘string’ type, whereas in C you have to use an array of ‘char’s.

-snip-
C++ does not force you to use cout for printing, you can still use printf even in C++. Every single feature that is part of C can still be used in C++.*
*This isn't technically true due to stuff like restrict and some minor type casting differences, but 99% of the time, they will act the same.
gem1001
Scratcher
1000+ posts

The C++ code language topic

ispretty wrote:

gem1001 wrote:

-snip-
C++ is an extended version from 1985:
#include <iostream>
using namespace std;
int main() {
  cout << "Hello, World!";
  return 0;
}
Whilst forcing you to manually pipe to cout instead of having a function like printf() seems like an abridgement rather than an extension, C++ does add new features; for example, there is a ‘string’ type, whereas in C you have to use an array of ‘char’s.

-snip-
C++ does not force you to use cout for printing, you can still use printf even in C++. Every single feature that is part of C can still be used in C++.*
*This isn't technically true due to stuff like restrict and some minor type casting differences, but 99% of the time, they will act the same.
OK.
Does make me wonder why they always tell you to pipe to cout though

Powered by DjangoBB