Hi guys, Im sort of new to coding and need help creating a program that will help me with somthing that I'm currently working on. My knowledge is extremely basic so I was only able to create a very simple form of what I actually need. Im sure there is better ways of doing this, but this is what I was able to do through quickly reading tutorials online. The code only does the first part of what I need it to do - it reads a file and then lists the model names to a seperate file. Here is the source code to what I currently have:
Basically I need a program that looks through 2 different .txt files and outputs specific data from these files into a seperate file..Code:#include <iostream> #include <fstream> #include <string> using namespace std; int main(int argc, char* argv[]) { ifstream in("datain.txt"); short int a1; string a2,a3,a4,a5,a6,a7,a8,a9,a10,a11; ofstream out("dataout.txt"); while(1) { if((in>>a1>>a2>>a3>>a4>>a5>>a6>>a7>>a8>>a9>>a10>>a11)) { out<<a2<<endl; } else break; } return 0; }
Sample input from text file:
(id, modelname, int, x, y, z, rotx, roty, rotz, int, LODindex) <- this part is not in the file.
I need the modelname part to be output to a list. If the last number of the line is -1 then ONLY the model name is needed. However, if the last number of the line is anything other than -1 then that number should be stored as it relates to a line number in the next file that will be read. So form the input above most of the lines have -1, but ros_townhall line ends with 37, so in this next file I need the program to go to line 37 in that file and store the model name on that line. I've been having difficulty finding how to get the program to go to a specific line, without the lines actually being numbered. When looking through the 2nd file, the program should skip over lines which start with "#" as these are just comments and should be ignored. The program should also skip over lines that contain 1 word such as "inst" or "objs"..# countn2_stream0.ipl
16683, cn2_alphabit01, 0, -426.523, 558.133, 16.352, 0.000, 0.000, -0.995, 0.098, -1
3336, cxrf_frway1sig, 0, -385.844, 547.844, 15.570, 0.000, 0.000, -0.996, 0.087, -1
700, sm_veg_tree6, 0, -436.711, 600.969, 16.172, 0.000, 0.000, 0.000, 1.000, -1
16224, s_bit_14, 1024, -428.641, 604.625, 1.961, 0.000, 0.000, 0.000, 1.000, 42
.........................
.........................
1294, mlamppost, 256, -280.383, 1123.414, 23.203, 0.000, 0.000, -1.000, -0.009, -1
16006, ros_townhall, 0, -215.234, 1119.195, 18.352, 0.000, 0.000, 0.000, 1.000, 37
669, sm_veg_tree4, 256, -225.312, 1127.211, 18.805, 0.000, 0.000, 0.000, 1.000, -1
1294, mlamppost, 0, -199.672, 1123.555, 23.203, 0.000, 0.000, -1.000, -0.000, -1
1468, DYN_MESH_05, 256, -232.758, 1129.758, 19.938, 0.000, 0.000, -1.000, 0.000, -1
1468, DYN_MESH_05, 256, -227.484, 1129.758, 19.938, 0.000, 0.000, -1.000, 0.000, -1
1294, mlamppost, 0, -186.461, 1123.398, 23.203, 0.000, 0.000, 0.000, 1.000, -1
16070, des_stwnhotel1, 0, -174.211, 1120.453, 24.406, 0.000, 0.000, 0.000, 1.000, 38
Sample input from the 2nd txt file that is read:
Line # < not part of the file just a comment by me. The actual file also does not have the lines numbered.
(this line is NOT COUNTED) inst
0 - 16265, des_damlodbit04, 1024, -606.0859375, 1910.101563, 9.140625, 0, 0, 0, 1, -1
1 - 16273, oilderricklod01, 0, 422.9140625, 1513.414063, 10.71875, 0, 0, 0, 1, -1
2 - 16274, oilderricklod02, 0, 435.0546875, 1269.6875, 8.6953125, 0, 0, 0, 1, -1
............................
............................
............................
35 - 3683, lod_indust1las, 0, 133.7421875, 1459.640625, 17.09375, 0, 0, 0, 1, -1
36 - 3289, lod_refthinchim1, 0, 207.5390625, 1371.242188, 9.5859375, 0, 0, 0, 1, -1
37 - 16412, lod_cn2townhall, 0, -215.234375, 1119.195313, 18.3515625, 0, 0, 0, 1, -1
38 - 16413, lod_stwnhotel1, 0, -174.2109375, 1120.453125, 24.40625, 0, 0, 0, 1, -1
Output should be a list like this:
Normal, Associated LOD
I just need all of the model names and their associated LOD names from these files. What would be the best way to achieve this? Thanks in advance to any help I receive.cn2_alphabit_01,
cxrf_frway1sig,
...............
...............
rostownhall, lod_cn2townhall
des_stwnhotel1, lod_stwnhotel1
...and so ON..