Vectors and functions question

This is a discussion on Vectors and functions question within the C++ Programming forums, part of the General Programming Boards category; Hi! I'm working on a group project that's due today and I'm receiving the following error: Code: .\GroupProject.cpp(169) : error ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    Vectors and functions question

    Hi! I'm working on a group project that's due today and I'm receiving the following error:

    Code:
    .\GroupProject.cpp(169) : error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'std::basic_string<_Elem,_Traits,_Ax>'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>,
                _Ax=std::allocator<char>
            ]
    for this line:
    Code:
    if((search2[index]==searchItem)&&(search4[index]>=1))
    when using this function:

    Code:
    void itemLookup(vector<string>& search1, vector<string>& search2, vector<int>& search3, vector<int>& search4, vector<int>& search5,
    				 vector<double>& search6, vector<double>& search7, int searchSize)
    {
    	int searchItem=0;
    	int index;
    	int selection=0;
    
    	cout<<"Please enter the name of the product to search for: "<<endl;
    	cin>>searchItem;
    
    	for(index=0; index<searchSize; index++)
    	{
    		if((search2[index]==searchItem)&&(search4[index]>=1))
    		{
    			cout<<"The item was found"<<endl;
    			cout<<"What information do you need about this item?"<<endl;
    			cout<<"1. Item Number"<<endl;
    			cout<<"2. Pieces Ordered"<<endl;
    			cout<<"3. Pieces In Store"<<endl;
    			cout<<"4. Pieces Sold"<<endl;
    			cout<<"5. Manufacturer Price"<<endl;
    			cout<<"6. Selling Price"<<endl;
    			cout<<"Please enter your selection 1-6: ";
    			cin>>selection>>endl;
    			if((selection<1)||(selection<7))
    			{
    				if(selection==1)
    				{
    					cout<<search1[index];
    				}
    				else
    					if(selection==2)
    					{
    						cout<<search3[index];
    					}
    					else
    						if(selection==3)
    						{
    							cout<<search4[index];
    						}
    						else
    							if(selection==4)
    							{
    								cout<<search5[index];
    							}
    							else
    								if(selection==5)
    								{
    									cout<<search6[index];
    								}
    								else
    									if(selection==6)
    									{
    										cout<<search7[index];
    									}
    			break;
    			}
    		}
    		else
    		{
    			cout<<"The store does not have this item."<<endl;
    			break;
    		}
    		}
    Am I able to compare vector values or is that why I am getting this error message? Any help would be greatly appreciated!
    Thanks!

    -Andrea

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    searchItem is declared as an int. search2[index] is a string. You are comparing a string to an int.

    BTW, giving more descriptive names to your variables is a good idea. For example, search2 could be itemNameList and search4 could be itemsInStore.
    Last edited by Daved; 03-28-2007 at 03:48 PM.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    16
    Thank you so much! I didn't even catch that, lol!

    -Andrea

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    vector2 is a vector of strings. You are comparing an std::string object and an integer.. I'd like to point you out that your whole design is weird and flawed. I don't mean to be rude though. You indented all the if's as if they were all imbricated (i.e. if selection == 1 and if selection == 2 and if selection == 3..) however you meant it (and coded it) to be separate if's. Don't do that. You have if((selection<1)||(selection<7)) which basically means that if something is between -INFINITE and +7, the condition is met. Therefore, would 'selection' be -12345 it would return true. All your vectors have the same name (except for the number at the end). How do you expect anyone who reads your code to know what's the difference between search1, search2, search3, search4.. ? If you had 20 different vectors, would you number them 1-20 ? That would create quite a mess. Give them all significant *different* names. The whole concept of using searchSize is wrong. Suppose searchSize is 5. What happens if selection is 5 for example and that search6 has 20 elements ? You will only scan through a quarter of the elements. In a similar fashion, what happens if search6 had 2 elements only ? You would have an out-of-bound error and your program would crash.

    Also, comments wouldn't hurt either.
    Last edited by Desolation; 03-28-2007 at 04:00 PM. Reason: Added last line.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    actually

    Actually, I've spent the whole day working on fixing this design. One of my peers in my class started with this and I'm basically on my own to fix it. It's frustrating. Anyway, thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  4. Type conversion question.
    By ellis in forum C++ Programming
    Replies: 5
    Last Post: 10-17-2006, 04:05 PM
  5. Replies: 2
    Last Post: 05-23-2003, 02:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21