error in code

Pages: 12
i have something like this

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
    vector <vector<vector<char>>> arrCompany;
    Buf = "carlsum, 22674, Carl Sum, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1";
    char chReturnStr[1024];
    char chReturnStrs[30];
    stringstream test(Buf);
    int lineCount = 0;
    while(test.getline(chReturnStr,1024))
    {
        if(lineCount>2)
        {
            stringstream tests(chReturnStr);
            int itemNo=0;
            int idItem=0;
            while(test.getline(chReturnStrs,30,','))
            {
                if(itemNo==0||itemNo==5||itemNo==6)
                {
                    arrCompany[lineCount-2][idItem]=chReturnStrs;
                    itemNo++;
                    idItem++;
                }
            }
        }
        lineCount++;    
    }



getting this error
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'char [30]' (or there is no acceptable conversion)

not sure what it means...sorry I am new to c++ so I have lots of questions...
Last edited on

vector <vector<vector<char>>> arrCompany;
...

char chReturnStrs[30];
...

arrCompany[lineCount-2][idItem]=chReturnStrs;


You declare arrCompany to have vector <vector<vector<char>>> which mean the final input is char. But later in your code, you are attempting to assign chReturnStrs which is declared as char[30].

You are trying to assign char[30] to char so of course there is no acceptable conversion.

i am not too sure if I declare it as char chReturnStrs that wont work as it will fail at getline
First you need to know what is the final input you want to store inside arrCompany ? You want to store char * izit ?

Then declare vector <vector<vector<char *>>> arrCompany and compile see how.
i want to store the stuff returned in getline(......

declaring it <vector<vector<char *>>> didnt work either
Try vector<vector<char []>>> arrCompany see how.
hahahah that caused like 40 errors....
beside that you have another problem. vector does not expand automatically with [] as you expect (map does, but that something else). use push_back().

furthermore instead of those char arrays use string:

1
2
3
4
5
std::string ReturnStr;
while(std::getline(test, ReturnStr))
{
  ...
}


that would simplify things. like std::vector <std::vector<std::string>> arrCompany;

Oh and Buf has not Typ (write const char *Buf = ... or something of that kind)
changing it to

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
std::vector <std::vector<std::string>> arrCompany;
string chReturnStr;
    string chReturnStrs;
    stringstream test(Buf);
    int lineCount = 0;
    while(std::getline(test,chReturnStr))
    {
        if(lineCount>2)
        {
            stringstream tests(chReturnStr);
            int itemNo=0;
            int idItem=0;
            while(std::getline(tests,chReturnStrs,','))
            {
                if(itemNo==0||itemNo==5||itemNo==6)
                {
                    arrCompany[lineCount-2][idItem]=chReturnStrs;
                    itemNo++;
                    idItem++;
                }
            }
        }
        lineCount++;    
    }


the error still exists....do you know what causes this error
I don't have any complier problems with it. what's the line number the compiler complains of?

yet another simplification/suggestion:

for(int lineCount = 0; std::getline(test,chReturnStr); lineCount++)
it complaining on this line

arrCompany[lineCount-2][idItem]=chReturnStrs;

i am using visual studio 2008

binary '=' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Last edited on
I'm able to compile it with visual studio 2008. It's a guess that there's something wrong with 'arrCompany' outside that code.

Are you aware that (if the compiler let you) that line will crash
what do you mean outside the code?

that means outside the code you posted here. Maybe a #define or something
closed account (EzwRko23)
 
std::vector <std::vector<std::string>> arrCompany;


Unless you are using a C++0x compatible compiler you have to write:

1
2
std::vector <std::vector<std::string> > arrCompany;
//                                  ^^^ a space here!!! 

Last edited on
I didnt do any #define for arrCompany..

even with the space std::vector <std::vector<std::string> > arrCompany;

it stills gives me an error
I finally found out your compilation error.

vector<vector<vector<string> > > arrCompany;
string test = "Can See?";
arrCompany[0][0] = test;

Above give compilation error like what you receive.

Change last line to below and it will compile ok.

arrCompany[0][0][0] = test;
OR
(arrCompany[0][0]).push_back(test);

The reason is arrCompany[0] will reference the second vector
The reason is arrCompany[0][0] will reference the third vector
To put element test into the third vector, you can use operator[] or push_back so

arrCompany[0][0][0] = test;
OR
(arrCompany[0][0]).push_back(test);

So for your case you can use below

(arrCompany[lineCount-2][idItem]).push_back(chReturnStrs);

or if you can control the index well

arrCompany[lineCount-2][idItem][new_index] = chReturnStrs;

In general for vector we like to use push_back rather than operator[] cuz what if we mess up the index and assign something in between leaving "empty" gaps in the vector ?






it causes an assertion now...

it fails here

1
2
3
4
5
6
7
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *message, const wchar_t *file, unsigned int line)
    {    // report error and die
        if(::_CrtDbgReportW(_CRT_ASSERT, file, line, NULL, message)==1)
        {
            ::_CrtDbgBreak();
        }
    }


on the line that is underlined
Last edited on
I am quite confused. The first posting code snippet is part of a big program is it ? It would then be hard to help you out if the program is really big.

Edit: I am assuming you store string in the third vector instead of char in your first posting cuz assign char[30] to char is an error.
Last edited on
it is alright i will spend sometime tomorrow to try to rectify all these issues....thanks alot for helping me out in my first encounter with vectors....cheers have a good friday nite......
Pages: 12