cprover
file_converter.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Convert file contents to C strings
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include <iostream>
13 #include <string>
14 
15 int main()
16 {
17  std::string line;
18 
19  while(getline(std::cin, line))
20  {
21  std::cout << "\"";
22 
23  for(std::size_t i=0; i<line.size(); i++)
24  {
25  const char ch=line[i];
26  if(ch=='\\')
27  std::cout << "\\\\";
28  else if(ch=='"')
29  std::cout << "\\\"";
30  else if(ch=='\r' || ch=='\n')
31  {
32  }
33  else if((ch&0x80)!=0)
34  {
35  std::cout << "\\x"
36  << std::hex << (unsigned(ch)&0xff)
37  << std::dec;
38  }
39  else
40  std::cout << ch;
41  }
42 
43  std::cout << "\\n\"\n";
44  }
45 }
main
int main()
Definition: file_converter.cpp:15