Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a sample that we used for cross-platform embeddeding of files. It's pretty simplistic, but will probably work for you.</p> <p>You may also need to change how it's handling linefeeds in the escapeLine function.</p> <pre><code>#include &lt;string&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;cstdio&gt; using namespace std; std::string escapeLine( std::string orig ) { string retme; for (unsigned int i=0; i&lt;orig.size(); i++) { switch (orig[i]) { case '\\': retme += "\\\\"; break; case '"': retme += "\\\""; break; case '\n': // Strip out the final linefeed. break; default: retme += orig[i]; } } retme += "\\n"; // Add an escaped linefeed to the escaped string. return retme; } int main( int argc, char ** argv ) { string filenamein, filenameout; if ( argc &gt; 1 ) filenamein = argv[ 1 ]; else { // Not enough arguments fprintf( stderr, "Usage: %s &lt;file to convert.mel&gt; [ &lt;output file name.mel&gt; ]\n", argv[0] ); exit( -1 ); } if ( argc &gt; 2 ) filenameout = argv[ 2 ]; else { string new_ending = "_mel.h"; filenameout = filenamein; std::string::size_type pos; pos = filenameout.find( ".mel" ); if (pos == std::string::npos) filenameout += new_ending; else filenameout.replace( pos, new_ending.size(), new_ending ); } printf( "Converting \"%s\" to \"%s\"\n", filenamein.c_str(), filenameout.c_str() ); ifstream filein( filenamein.c_str(), ios::in ); ofstream fileout( filenameout.c_str(), ios::out ); if (!filein.good()) { fprintf( stderr, "Unable to open input file %s\n", filenamein.c_str() ); exit( -2 ); } if (!fileout.good()) { fprintf( stderr, "Unable to open output file %s\n", filenameout.c_str() ); exit( -3 ); } // Write the file. fileout &lt;&lt; "tempstr = "; while( filein.good() ) { string buff; if ( getline( filein, buff ) ) { fileout &lt;&lt; "\"" &lt;&lt; escapeLine( buff ) &lt;&lt; "\"" &lt;&lt; endl; } } fileout &lt;&lt; ";" &lt;&lt; endl; filein.close(); fileout.close(); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload