c++ - How do I use quotation marks in fstream? -


i want output line .plt file says "one-d hydro" double quotation marks , far have problem.

#include <cstdlib> #include <fstream>  using namespace std;  int main() {         fstream gnuplot_file;                  gnuplot_file.open ("sod.plt");         gnuplot_file<<"set title"<< ""one-d hydro""<<std::endl;         gnuplot_file.close();         system("gnuplot.exe sod.plt");           return 0; } 

line 11 not allow compile because can't seem close statement. error useless way.

gnuplot_call.cpp|11|error: expected ';' before 'one'|

with c++03 (or c) use backslashes escapes double-quotes in string literals:

    gnuplot_file << "set title" << "\"one-d hydro\"" << std::endl; 

notice gnuplot may require escape characters, e.g. if wanted title contain quotes!

with c++11 use raw string literals, e.g.

   gnuplot_file<< r"*(set title "one-d hydro")*" << std::endl; 

btw, interested popen(3) , pclose, if operating system , c++ library provides them. popen gnuplot process , send commands it, pclose-ing it.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -