* for argument `1' to `int strcmp(const char*, const char*)
@ 2004-09-01 14:20 learning c++
0 siblings, 0 replies; 2+ messages in thread
From: learning c++ @ 2004-09-01 14:20 UTC (permalink / raw)
To: gcc-help
Hi,
I hope to use the build in function ""strcmp()" in C++, but I can not deal
with it. My code is like this:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int main(){
vector<string> v1;
vector<string>::iterator iter;
string s;
do{
cout <<"please input something:" <<endl;
cin>>s;
v1.push_back(s);
}while (!(strcmp(s,"quit")));
for(iter=v1.begin(); iter!=v1.end();iter++)
cout <<*iter<<endl;
return 0;
}
error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > >'
to
`const char*' for argument `1' to `int strcmp(const char*, const char*)'
I know now "s" is an object of string. How can I compare it with a string,
like ""quit"? Are there some methods in String class?
Thanks,
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: for argument `1' to `int strcmp(const char*, const char*)
@ 2004-09-01 16:44 lrtaylor
0 siblings, 0 replies; 2+ messages in thread
From: lrtaylor @ 2004-09-01 16:44 UTC (permalink / raw)
To: learning_c, gcc-help
You can pass a string object to strcmp like that. You have to pass it a
character array instead.:
strcmp(s.c_str(), "quit");
For that matter, though, you can just do this:
while ( s == "quit" )
unless you're trying to loop until s is quit, in which case you're logic
is wrong with strcmp, too.
while ( s != "quit" )
Thanks,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of learning c++
Sent: Wednesday, September 01, 2004 8:17 AM
To: gcc-help@gcc.gnu.org
Subject: for argument `1' to `int strcmp(const char*, const char*)
Hi,
I hope to use the build in function ""strcmp()" in C++, but I can not
deal
with it. My code is like this:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int main(){
vector<string> v1;
vector<string>::iterator iter;
string s;
do{
cout <<"please input something:" <<endl;
cin>>s;
v1.push_back(s);
}while (!(strcmp(s,"quit")));
for(iter=v1.begin(); iter!=v1.end();iter++)
cout <<*iter<<endl;
return 0;
}
error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char>
> >'
to
`const char*' for argument `1' to `int strcmp(const char*, const
char*)'
I know now "s" is an object of string. How can I compare it with a
string,
like ""quit"? Are there some methods in String class?
Thanks,
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-09-01 16:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-01 14:20 for argument `1' to `int strcmp(const char*, const char*) learning c++
2004-09-01 16:44 lrtaylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).