C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 26th, 2005, 01:35 AM
codemonkey2525 codemonkey2525 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 codemonkey2525 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m
Reputation Power: 0
Question vector <string> comparsion to string in c++

I have two probelms. First, I am trying to compare a vector <string> to a string and produce the following error:
'operator+' not implemented in type 'vector<string,allocator<string> >' for arguments of type 'string *'

Secondly, I get the following two errors when i am trying to copy a string into a char:
Cannot convert 'int' to 'char *'
Type mismatch in parameter '__dest' (wanted 'char *', got 'char')

Here is the code I am using:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <vector.h>
#include <conio>
#include <string>
using namespace std;
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
char filename1[25], filename2[25];
vector<string> codeTable;
ifstream inStream;
ofstream outStream;
string tempString, temp;
char c, buffer1;
bool found = false;
int n = 10;
cout << "Please enter a file name that you wish to compress:";
cin >> filename1;
cout << "Please enter:";
cin >> filename2;
inStream.open(filename1);
temp = '1';
codeTable.push_back(temp);
temp = '2';
codeTable.push_back(temp);
temp = '3';
codeTable.push_back(temp);
temp = '4';
codeTable.push_back(temp);
temp = '\n';
codeTable.push_back(temp);
inStream.get(buffer1);
while (!inStream.eof())
{
inStream.get(c);
tempString = buffer1 + c;
for (vector<string>::iterator i = codeTable.begin(); i != codeTable.end(); ++i)
{
if (tempString == codeTable[i]) // First error occurs here
{
found=true;
break;
}
}
if(found == true)
strcpy(buffer1, tempString.c_str()); // Second and third error is here
else
{
outStream << buffer1;
codeTable[n] = tempString;
n++;
buffer1 = c;
}
}
outStream << buffer1;
cout << "Press any key";
getch();
return 0;
}

Thanks for the help!

Reply With Quote
  #2  
Old March 26th, 2005, 12:30 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 296 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 13 h 30 m 11 sec
Reputation Power: 14
For first bold text: You are comaparing a character to a string. In other words, comparision is done for an array of characters to a single character.

Second error is because a character is treated as an integer of range 0-256.
For correction: Convert the single character to a single character string and then appyly string operations.

Reply With Quote
  #3  
Old May 19th, 2008, 02:05 PM
skyline6 skyline6 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 skyline6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 56 sec
Reputation Power: 0
Hey, umm... i need some help...

I have trouble with strings inside victors,
program wownt let me do it and i get a bunch of crap...



#include<iostream.h>
#include<iomanip.h>
#include<vector.h>

int main()
{
vector<int>make;
vector<int>model;
int num_cars;
float HP=0;
float Torque=0;
int index;//counter for loops

//promt user for the numbers of cars they want to enter
cout<<"How many cars are in your group? ";
cin>>num_cars;

//Resize vectors to the lenght necessary to hold
//the specific number of races
make.resize(num_cars);
model.resize(num_cars);

//promt user for values for each child
for(index =0; index <=(num_cars-1); index++)
{
cout<<"Car#"<<index+1<<":\n";
cout<<"Car Make: ";
cin>>make[index];
cout<<"Model: ";
cin>>model[index];
}

//print a table of the results
cout.setf(ios::right);
cout.setf(ios::fixed);
cout<<setprecision(2);
cout<<"\n\nResults Table\n";
cout<<setw(10)<<"make"<<setw(10)<<"model"<<endl;

cout<<endl;

system("pause");
return 0;
}


Thats the code and i need to type letters but it gives me out a bunch of messages... please help anyone??

thanks you...

Reply With Quote
  #4  
Old May 19th, 2008, 02:29 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Works for me. But I changed some things:
#include <iostream> instead of iostream.h
the same for the remaining two header files. I added
using namespace std;
to make it compile without further changes.

By the way, why didn't you just make a new thread for this post?
__________________
There is no such thing as C/C++, you either program C or C++

Reply With Quote
  #5  
Old May 20th, 2008, 02:54 PM
skyline6 skyline6 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 skyline6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 56 sec
Reputation Power: 0
...

well, i just got on this site 4 some help... and i had like 5 minutes to do, i couldnt find the option so i did what i could...

thnks a lot, i didnt even notice that i didnt have the using namspace std thing...,

i made those changes but it still wownt work.. i need to enter letters for the first two and numbers for the 3d and 4th... and it wownt let me do it..

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > vector <string> comparsion to string in c++


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap