Question

I'm trying to write a part of a C++ file to output text to a file to be read by gnuPlot. I want to include the characters { and } in my output file, so that gnuplot can read them in a style similar to that used by laTex.

The relevant section of my code reads

std::ofstream gnuplotFile2;
gnuplotFile2.open("FourierImages.gpi");
gnuplotFile2 << "set xlabel \"Wavenumber (m^" << '\\\u007B' << "-1" << '\} << "\"\n";

Here, I've used both \u007B and } to try and output { or }. I've also tried including just "...(m^{-1})\n"; and "...(m^\{-1\}\m";.

My output file always reads

set xlabel "Wavenumber (m^-1)"

which produces a graph/chart with the label having the - character in superscript, but the 1 as normal script.

How can I output the { and } characters to a file? I would like

set xlabel "Wavenumber (m^{-1})"
Was it helpful?

Solution

Unless I'm missing something, just use the characters { and }, like this

$ cat test.cc
#include <iostream>
#include <fstream>

int main() {
  std::ofstream gnuplotFile2;
  gnuplotFile2.open("FourierImages.gpi");
  gnuplotFile2 << "set xlabel \"Wavenumber (m^{" << "-1" << "})\"\n";
}

$ g++ test.cc && ./a.out && cat FourierImages.gpi
set xlabel "Wavenumber (m^{-1})"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top