WriteProgramWhen the configuration file is used, you can select Lua if Lua is more suitable.
At the beginning, all configurations are loaded from the file, and it is OK to directly call a function. Later, the program will run normally if the configuration file does not exist, so the program needs to be configured by default.
But I don't want to change the original structure. I want to hard encode the default configuration script in the program in the form of a string. In this case, I encountered a problem: the default configuration is about 6 ~ The size of 7 K. If a row is knocked, it must be very uncomfortable ......
This repetitive work should be handed over to the computer, and the final decision is to put this partCodeLet the computer write (I wrote it before, and it just copies it *_*)......
But don't write it. Well, let me write a Python code to teach it:
1 # ! /Usr/bin/Python
2 # Filename: writecode. py
3 # Author: Mike
4 # E-mail: Mike_Zhang@live.com
5
6 Import String
7
8 Endlinepos =-1 # Windows '\ N'
9 # Endlinepos =-2 # Linux '\ r \ N'
10
11 Fin = file ( " CNF. Lua " , " R " )
12 Fout = file ( " Code. cpp " ," W " )
13 Srcstr = ' \" '
14 Dststr = ' \\\" '
15 Varnamestr = " Luascriptstr "
16
17 For Line In Fin. readlines ():
18 If Not Line. Split (): Continue
19 Tmp2 = ''
20 Tmp2 + = varnamestr
21 Tmp2 + = ' + = \" '
22
23 If Line. Count (srcstr)> 0:
24 Nstartpos = 0
25 NPOs = 0
26 While True:
27 NPOs = line. Find (srcstr, nstartpos)
28 If NPOs =-1:
29 Tmp2 + = line [nstartpos: endlinepos:]
30 Break
31 Tmp2 + = line [nstartpos: NPOs:]
32 Tmp2 + = dststr
33 Nstartpos = NPOs + Len (srcstr)
34 Else :
35 Tmp2 + = line [: endlinepos:]
36 Tmp2 + = ' \ N \ "; \ n '
37 Print Tmp2,
38 Fout. Write (tmp2)
39 Fout. Close ()
40 Fin. Close ()
41 Raw_input ()