error in code

Pages: 12
yea i store string and changed the char to strings on advice of one of the comments here
Do you have a debugger to step through your code snippet line by line? If not put cout statement on important lines to determine which line trigger the error. I am sorry I don't have the time to trace it out for you. Debugging source code is part and parcel and valuable skill-set all developers should have in their programming career :P
yup i found out which line but am unable to solve the issue of why it causes that error...
Which line is it?.
arrCompany[lineCount-2][idItem]=chReturnStrs;
ok it seems that there're some major problems in understanding what's going on. So here's the working 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
#include <iostream>

#include <vector>
#include <string>
#include <sstream>

using namespace std;

const char *const Buf = "carlsum1, 22674, Carl Sum 1, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum2, 22674, Carl Sum 2, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum3, 22674, Carl Sum 3, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum4, 22674, Carl Sum 4, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1";


int main()
{
    stringstream complete_stream(Buf);
    vector<vector<string> > arrCompany;
    string line;
    for(int lineCount = 0; getline(complete_stream, line); ++lineCount)
    {
        if(lineCount>2)
        {
            cout << "Line: " << line.c_str() << endl;
            stringstream line_stream(line);
            vector<string> line_part_vector;
            string line_part;
            for(int itemNo=0; getline(line_stream, line_part,','); ++itemNo)
            {
                if(itemNo==0||itemNo==5||itemNo==6)
                {
                    cout << "Line part " << itemNo << ": " << line_part.c_str() << endl;
                    line_part_vector.push_back(line_part);
                }
            }
            arrCompany.push_back(line_part_vector);
        }
    }

    return 0;
}


I renamed some variables so that it may make it more clear what's going on there.

so carlsum1986 if you take that code be careful not to mix it up
it is perfect now thanks alot
Hi calrsum1986, coder777 changes your data structure variable to vector<vector<string> > arrCompany; This is important. Make sure you know why he uses above instead of your earlier vector<vector<vector<string> > > arrCompany;
this reduces it by one dimension right?
Correct but the gist is why coder777 opt to use 2 dimension and earlier you opt to use 3 dimension? If coder777 delivered your expected output then in your earlier 3 dimension design did you designed it wrongly ?

Using the correct Data Structures and Algorithm are very important in computer programs.
yes I designed it wrongly cause I thought vector<vector<vector<string>>> arrCompany; was two dimension and this was causing all kinds of errors.....
beginner's mistake....
Topic archived. No new replies allowed.
Pages: 12