-3
cout << key;    
cout << " " << temp_char << " - " << key_char << " " << (temp_char-key_char) << endl;

enter image description here

    /*
 * Function: StringToInteger
 * Usage: n = StringToInteger(s);
 */

int StringToInteger(string str)
{
    int returnVal;
    istringstream result(str);
    string rest;

    if ((result >> returnVal).fail()) {
    Error("Not a valid number!");
    }
    result >> rest;
    if (rest != "") {
    Error("Extra characters not allowed");
    }
    return returnVal;
}

void Lexicon::buildMapFromFile(string filename )  //map
{
    ifstream file;
    file.open(filename.c_str(), ifstream::binary);
    string mem, key;
    string wow;
    unsigned int x = 0;

    cout << endl;
    string temp;

    while(true) {
        getline(file, wow);
        if (file.fail()) break; //boilerplate check for error
        while (x < wow.length() ) {
            if (wow[x] == ',') { //look for csv deliniator
                key = mem;
                mem.clear();
                x++; //step over ','
            } else 
                mem += wow[x++];
        }

        char key_char = (char)StringToInteger(key); //cast integer into a char
        key = key_char; //change from char to string for the map

        cout << key_char << " is " << (temp[0]-key[0]) << " " << mem << " " << endl;

        tokenToChar_map[key] = mem; //char to string
        charToToken_map[mem] = key; //string to char
        mem.clear(); //reset memory
        x = 0;//reset index
        temp = key;
    }
    //printf("%d\n", tokenToChar_map.size());
    file.close();
}

A section of the input file:

103,089
104,090
105,091
106,092
107,093
108,094
109,095
110,096
111,097
112,098
113,099
114,100
115,101
116,102
117,103
118,104
119,105
120,106
121,107
122,108
123,109
124,110
125,111
126,112
127,113
128,114
129,115
130,116
131,117
132,118
133,119
134,120
135,121
136,122
137,123
138,124
139,125
140,126
141,127
142,128
143,129
144,130
145,131
146,132
147,133
148,134
149,135
150,136
151,137
152,138
180,RW4
181,R1
182,RW1
183,NBE
184,RW3
185,NB0
186,D1
187,EPS
188,C0
189,0M0
190,C1
191,RWY
192,D2
193,SB0
194,SBE
195,R2
196,RW2
197,RW5
210,0A1
211,0B2
212,0B3
213,0B4
214,0A5
250,*
251,?
252,z
253,test
254,test
255,test

Integers 7,8,9,10,11,12, and 13 do not have an associated char

Integers 114 <-255>, 180 <28>, 210 <13>, and 250 <36> are more than 1 away from their predecessor integer

what is going on, why are these not sequential?

4

1 回答 1

1

Look at your input data:

[...]
152,138
180,RW4
[...]
197,RW5
210,0A1
[...]
214,0A5
250,*
[...]

What is wrong with (char)StringToInteger("152") - (char)StringToInteger("180") producing -28?

If you can't tell us what you specifically what you expect your program to output, we can't help you with this question.

于 2013-01-18T23:37:09.620 回答