gpt4 book ai didi

c++ - 将字 rune 字 { 输出到 fstream C++

转载 作者:行者123 更新时间:2023-11-28 07:12:23 25 4
gpt4 key购买 nike

我正在尝试编写 C++ 文件的一部分以将文本输出到文件以供 gnuPlot 读取。我想在我的输出文件中包含字符 { 和 },以便 gnuplot 可以以类似于 laTex 使用的样式读取它们。

我的代码的相关部分是

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

在这里,我同时使用了\u007B 和 } 来尝试输出 { 或 }。我也试过只包括 "...(m^{-1})\n";和“...(m^\{-1\}\m”;.

我的输出文件总是读取

set xlabel "Wavenumber (m^-1)"

它生成一个图形/图表,标签上标有 - 字符,但 1 作为普通脚本。

如何将 { 和 } 字符输出到文件?我愿意

set xlabel "Wavenumber (m^{-1})"

最佳答案

除非我遗漏了什么,只需使用字符 {},就像这样

$ 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})"

关于c++ - 将字 rune 字 { 输出到 fstream C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20769601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com