Warning: Identifier was truncated to 255 characters

Thanks in advance for any help yall can give me. I'm not sure what to make of these warnings my compiler is giving me..
This is my first time messing with vectors, and was trying to write a function that gets lines from a text file and checks a substring from each line with a vector of strings to see if it matches with a previous occurence. Eventually I was gonna have them combine as a new unit by adding the multipliers and blah blah but went to compile the bit I had and got this warning:

identifier was truncated to '255' characters in the debug information

I ignored the warnings and hit run and it crashed.

again, this is my first time using vectors, so I went with my usual strategy of making the simplest code possible and adding little bits from there.
Once I started compiling my test code with a vector of strings I got the same warnings, but the thing ran and didn't crash. Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    vector <int> v_series;
    vector <string> v_strings;

    for (int x=0; x!=10; x++)
    {
        v_series.push_back(x+1);
        v_strings.push_back("blah blah.");
    }

    for (int w=0; w!=10; w++)
    {
        cout << v_series.at(w) << " "
            << v_strings.at(w) << "\n";
    }

    return 0;
}


That runs ok, but gives me that same warning..
So I was really confused when I went to clean up my original code a little to post it, compiled it to check for syntax prollems, and it ran without crashing!
All the warnings from compiler are still there, but it reminded me of a time I had a program crash the same way, because it wasn't reading from the text file right. Then I started wondering if the error that caused my new code to crash might have nothing to do with the 'identifier truncated' warnings, but instead maybe it crashed because I am doing something wrong with the loop that has getline()?
Anyways, here's the problem code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define MAT_UNIT_CHAR "5"
#define DO_PRINT_OCCURENCE 1

// ... gonna skip a bit here ...

void combine_units()
{
    fstream fs_units("units.txt", ios::in | ios::out);
    if (fs_units.is_open()) { cout << "units.txt is open.\n"; }
        // gonna make some "else" stuff here..
    vector <string> v_mat_id_list;
    vector <unsigned int> v_occurence;

    string s_unit_ref, s_combined_ref, s_unit_id,
        s_unit_type, s_mat_ref, s_mltx_ref;

    unsigned short int did_match;

    while (fs_units.good())
    {
        getline(fs_units, s_unit_ref);
        s_unit_id = s_unit_ref.substr(0,4);
        s_unit_type = s_unit_ref.substr(4,1);

        if ((s_unit_type == MAT_UNIT_CHAR) & (s_unit_id != "null"))
        {
            s_mat_ref = s_unit_ref.substr(5,6);
            s_mltx_ref = s_unit_ref.substr(11,4);
            s_combined_ref = s_unit_ref.substr(5,10);

            did_match = 0;
            for (int x=0; x < v_occurence.size(); x++)
            {
                if (s_combined_ref == v_mat_id_list.at(x))
                {
                    v_occurence.at(x)++;
                    did_match = 1;
                }
            }

            if (did_match == 0)
            {
                v_mat_id_list.push_back(s_combined_ref);
                v_occurence.push_back(1);
            }
        }
    }

    if (DO_PRINT_OCCURENCE == 1)
    {
        for (int w=0; w < v_occurence.size(); w++)
        {
            cout << "material code: " << v_mat_id_list.at(w)
                << "appears " << v_occurence.at(w) << " ";
            if (v_occurence.at(w) == 1)
            { cout << "time.\n"; }
            else
            { cout << "times.\n"; }
        }
    }

    fs_units.close();
    cout << "units.txt closed.\n";
}


.. and here's the text file "units.txt":

null5mat_idmltx
u0000m0000a0010
u0015m0000a0100
u0025m0000a0100
u0035m0000a0100
u0045m0000b0100
u0055m0000b0100
u0060m0000b0100
u0075m0000c0100


btw, I know there's extra variables I'm not using atm..
and I know did_match should be boolean..
and I'm using {} containing just a single statement after if..
but any input on this would be greatly appreciated.

What do these warnings mean? Did they make my program crash, or was it something else entirely? The crash reminded me of when I was learning fstream and wrote a bogus loop to getline() from file until .good() == FALSE.. it compiled with no warnings then crashed. Now that I've cleaned up that code ^ above to post it, I can't get it to crash, but I still have the warning from compiler. That's what was making me think they were two separate issues there.. I'm scared to keep going until I figure this out.

and a couple other things was curious about..
Do I even need "#include <string>" when i've included <sstream>?
Do variables declared within the () of a for loop exist after the loop ends?

Sorry, I know this is kind of an open ended post but really am not sure what the problem is.
-cPlusN()()b

GO RAVENS >x3
might have nothing to do with the 'identifier truncated' warnings, but instead maybe it crashed because I am doing something wrong with the loop that has getline()?

That's right. In my test (with main() simply calling combine_units()), program terminates when string.substr() throws an exception, and that happens when you read past the end of file.

The fix is simple: use correct I/O loops:

instead of
1
2
3
    while (fs_units.good())
    {
        getline(fs_units, s_unit_ref);

use
1
2
3
    while (getline(fs_units, s_unit_ref))
    {
        
Last edited on
Ah so
That's where it was crashing. Thanks Cubbi! :3
I feel a lot better about going ahead with the code now.
lol hell with the warnings, I'll figure that out later. Important thing is, now it's not crashing.
Topic archived. No new replies allowed.