Or you can use a raw string literal introduced in C++ 2011. In this case there is no need to double \ and to use \" instead of ".
I advice to use a raw string literal.
For example
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
int main()
{
std::string s( R"(awk 'BEGIN {printf "x\n%10s\t%10s\n", "Vol", "Current"}{if($1+0==$1){printf "%10.5f\t%10.5f\n", $2, $3}} END {printf "y\n"}')" );
std::cout << s << std::endl;
return 0;
}
Hi,
I have tried to Raw string but it did not accept.Do I need any other header file. I added in string file. or as we have legacy header file. do I need update string header file
gcc version:
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)
1 2 3 4 5 6 7 8 9
put.cpp:6: error: `R' was not declared in this scope
put.cpp:6: error: stray '\' in program
put.cpp:6:52: invalid suffix "s" on integer constant
put.cpp:6: error: stray '\' in program
put.cpp:6:58: invalid suffix "s" on integer constant
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program
put.cpp:6: error: stray '\' in program
No header is required to use raw string literals. It seems that you are using an old compiler that does not support raw string literals.
To be sure that string literals are useful you can check my code on-line at www.ideone.com selecting C++11 ( gcc 4.7.2).
If you have no a possibility to use a newer compiler then you should do as I pointed out in my first post.