JSFiddle - React, Tailwind, and code Playground

HTML

<form onsubmit="download(this['name'].value, this['text'].value);return false;">
<input type="text" id="cpp-code" value="test.txt">

<div><textarea id="cpp-code">
//This is a C++ Text Editor. Enter you c++ code below, this line is a comment.
 
</textarea></div>

  <input type="submit" value="Download">
</form>

JavaScript

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}