Parsing a text file?

I'm trying to learn how to parse a text file, ideally I want to find and change just the numerical values and output the file with the same formatting.

Using getline with a string variable strips the lines of the newline character. What is the best way to go about parsing a program/code file to modify values and then reoutput them?

Here is a sample textfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
UnitBlueprint {
    Merge = true,
    BlueprintId="uel0401",

Defense = {
        ArmorType = 'Normal',
        Health = 30000,
        MaxHealth = 30000,
        RegenRate = 7,
        Shield = {
            ShieldEnergyDrainRechargeTime = 2,
            ShieldMaxHealth = 45000,
            ShieldRechargeTime = 50,
            ShieldRegenRate = 300,
            ShieldRegenStartTime = 120,
            ShieldSize = 25,
            ShieldVerticalOffset = -3,
        },
    },
closed account (Lv0f92yv)
If you use getline, you can read each character one at a time, determine what it is (a numerical value?), and if it is what you want to change, write a new value to a different string. Otherwise, write the value you read in. Once you finish iterating over the string, add the '\n' character for your newline. Then write that new string to a new file.
Topic archived. No new replies allowed.