|
s1 is CString
then can use
CompareNoCase
Compare
|
|
|
|
|
in fact i think i did not express the problem correctly: i don´t want to egalise two string, but to compare two strings. ( sorry for my english)
|
|
|
|
|
Yes, if S1 and S2 are CString, operators (<, <=, >=, >, ==, and !=) works very well.
If they are char streams, use strcmp function. Operator overloading is not done for char streams.
|
|
|
|
|
in fact i think i did not express the problem correctly: i don´t want to egalise two string, but to compare two strings. ( sorry for my english)
|
|
|
|
|
in fact we understood rightly.
== operaotr compares not equalizes.
|
|
|
|
|
mandanani wrote: == operaotr compares not equalizes
then why does the code:
<br />
c1='aaa bbb ccc';<br />
f1='aaa bbb ccc'; <br />
cout<<c1<<endl;cout<<f1<<endl;<br />
if (c1 == f1) <br />
{a1=1;}<br />
cout<<a1;<br />
<br />
<br />
return on screen:
c
c
0
|
|
|
|
|
I think you have to understand how strings function. What are c1 and f1 ? char pointers, std::string or CString ? Without knowing that we can't really help you.
If these are standard char pointers, you need to use strcpy to be able to store one string in the array (but first, it must be allocated with enough size). Then, you can compare two strings using strcmp function.
Everything has already been told before.
So a code example:
char string1[255];<br />
char string2[255];<br />
<br />
strcpy(string1,"Test");<br />
strcpy(string2,"Test");<br />
if (strcmp(string1,string2) == 0)<br />
cout << "Strings are equal";<br />
else<br />
cout << "Strings are different";
Check the documentation of the functions on MSDN to be sure you understood correctly the concept.
|
|
|
|
|
but what does equalize mean for you ??
and in what does it differ from comparing 2 strings ?
also, don't hesitate to tell what kind of string you use (me know that you use std::string, but most people who replied here didn't know that, hence the CString references) to avoid bad answers
|
|
|
|
|
toxcct wrote: me know that you use std::string
How do you know that ??
|
|
|
|
|
Cedric Moonen wrote: How do you know that ??
I suspect he made an assumption based on the fact the code was using the '==' operator to attempt the comparison, but could obviously be wrong.
|
|
|
|
|
I think the OP was using the == operator with char pointers and that's why it didn't work.
|
|
|
|
|
because he asked a question related 2 posts below
check this[^]
|
|
|
|
|
If somebody is motivated to understand that, i have tried to regroup and order the programme. I hope you will help me.
#include <cstdlib><br />
#include <iostream><br />
using namespace std;<br />
#include<fstream><br />
#include<stdio.h> <br />
#include <time.h><br />
#include <sstream><br />
#include<string><br />
<br />
int main()<br />
{<br />
<br />
<br />
fstream list;<br />
list.open("listfile.txt",ios::in);<br />
<br />
char t;<br />
int i;<br />
string s1;<br />
string s2;<br />
string s3;<br />
string s4;<br />
string s5;<br />
string s6;<br />
string s7;<br />
string s8;<br />
string s9;<br />
string s10;<br />
string s11;<br />
<br />
<br />
getline(list,s1);cout<<s1<<endl;<br />
getline(list,s2);cout<<s2<<endl;<br />
getline(list,s3);cout<<s3<<endl;<br />
getline(list,s4);cout<<s4<<endl;<br />
getline(list,s5);cout<<s5<<endl;<br />
getline(list,s6);cout<<s6<<endl;<br />
getline(list,s7);cout<<s7<<endl;<br />
getline(list,s8);cout<<s8<<endl;<br />
getline(list,s9);cout<<s9<<endl;<br />
getline(list,s10);cout<<s10<<endl;<br />
getline(list,s11);cout<<s11<<endl;<br />
<br />
<br />
time_t date_codee;<br />
tm * date;<br />
ostringstream ostr(ostringstream::out);<br />
date_codee = time(NULL);<br />
date = localtime(&date_codee);<br />
ostr << "clippr-" <br />
<< date->tm_mday <br />
<<"-"<br />
<< date->tm_mon + 1 <br />
<<"-"<br />
<< date->tm_year + 1900<br />
<< ".txt";<br />
<br />
<br />
<br />
int a1=0;<br />
int a2=0;<br />
int a3=0;<br />
int a11=0;<br />
int a4=0;<br />
int a5=0;<br />
int a6=0;<br />
int a7=0;<br />
int a8=0;<br />
int a9=0;<br />
int a10=0;<br />
char c;<br />
char t1;<br />
char t2;<br />
char t3;<br />
char t11;<br />
char t4;<br />
char t5;<br />
char t6;<br />
char t7;<br />
char t8;<br />
char t9;<br />
char t10;<br />
char f;<br />
<br />
<br />
fstream clippr;<br />
clippr.open("clippr.txt",ios::in);<br />
<br />
<br />
fstream fichier1;<br />
fichier1.open(s1.c_str(),ios::in);<br />
<br />
fstream fichier2;<br />
fichier2.open(s2.c_str(),ios::in); <br />
<br />
fstream fichier3;<br />
fichier3.open(s3.c_str(),ios::in);<br />
<br />
fstream fichier11;<br />
fichier11.open(s11.c_str(),ios::in);<br />
<br />
fstream fichier4;<br />
fichier4.open(s4.c_str(),ios::in);<br />
<br />
fstream fichier5;<br />
fichier5.open(s5.c_str(),ios::in);<br />
<br />
fstream fichier6;<br />
fichier6.open(s6.c_str(),ios::in);<br />
<br />
fstream fichier7;<br />
fichier7.open(s7.c_str(),ios::in);<br />
<br />
fstream fichier8;<br />
fichier8.open(s8.c_str(),ios::in);<br />
<br />
fstream fichier9;<br />
fichier9.open(s9.c_str(),ios::in);<br />
<br />
fstream fichier10;<br />
fichier10.open(s10.c_str(),ios::in);<br />
<br />
<br />
string c1;string c2; string c3;<br />
string f1;string f2; string f3;<br />
getline(clippr,c1);<br />
getline(clippr,c1);cout<<c1<<endl;<br />
getline(clippr,c2);cout<<c2<<endl;<br />
getline(clippr,c3);cout<<c3<<endl;<br />
<br />
getline(fichier1,f1);<br />
getline(fichier1,f1);cout<<f1<<endl;<br />
getline(fichier1,f2);cout<<f2<<endl;<br />
getline(fichier1,f3);cout<<f3<<endl;<br />
<br />
<br />
if (c1==f1&&c2==f2&&c3==f3) <br />
{a1=1;}<br />
<br />
<br />
clippr.close();<br />
fichier1.close();<br />
fichier2.close();<br />
fichier3.close();<br />
fichier11.close();<br />
fichier4.close();<br />
fichier5.close();<br />
fichier6.close();<br />
fichier7.close();<br />
fichier8.close();<br />
fichier9.close();<br />
fichier10.close();<br />
<br />
if (a1==1) {cout<<"fichier1 is not clippr"<<endl; }<br />
if (a2==1) {cout<<"fichier2 is not clippr"<<endl; }<br />
if (a3==1) {cout<<"fichier3 is not clippr"<<endl; }<br />
if (a11==1){cout<<"fichier11 is not clippr"<<endl; }<br />
if (a5==1) {cout<<"fichier5 is not clippr"<<endl; }<br />
if (a4==1) {cout<<"fichier4 is not clippr"<<endl; }<br />
if (a6==1) {cout<<"fichier6 is not clippr"<<endl; }<br />
if (a7==1) {cout<<"fichier7 is not clippr"<<endl; }<br />
if (a8==1) {cout<<"fichier8 is not clippr"<<endl; }<br />
if (a9==1) {cout<<"fichier9 is not clippr"<<endl; }<br />
if (a10==1){cout<<"fichier10 is not clippr"<<endl; }<br />
<br />
<br />
if (a1==0) {cout<<"fichier1 is clippr"<<endl;<br />
rename(s1.c_str(), ostr.str().c_str());}<br />
<br />
<br />
<br />
cin>>t1;}<br />
|
|
|
|
|
very bad thing to post a huge block of code and tell to anyone to see what's wrong with it...
you must post relevant samples, and try to understand which are the incriminated lines.
and use your debugger if you can
|
|
|
|
|
if(strcmp(s1,s2)==0)
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
s1 and s2 are std::strings...
|
|
|
|
|
Et cela pose problème?
|
|
|
|
|
pourquoi tu le prend comme ca ? je le signalais juste à celui qui te répondait que son code ne marche que si ce sont des char*, pas des strings
|
|
|
|
|
OK, ragazzi, ora, rilassatevi...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
uhh, sorry, i don't understand much italian ! lol
|
|
|
|
|
Oh, pardon,
I assumed it was a multi-ethnic thread...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Oula je ne suis pas du tout enervé, choqué, ou autre. Je bois les paroles de tous ceux qui postent un message sur ce forum car je n´ai a mon actif ke 30h de langage c++. Je n´y connais pas grand chose.
Je suis actuellement en stage et je dois realiser ce programme. Cela fait maintenant une semaine que je suis dessus, et je sens qu´il est tout près d´aboutir.
Désolé si ma réponse a pu paraitre sèche, ce n´etait pas du tout l´esprit du message. C´est l´effet message ecrit qui ne transcrit pas le ton de la voix.
|
|
|
|
|
ok, let's continue in english now.
you still didn't answered a question of mine...
what, for you, is the difference between equalize and compare 2 strings ?
|
|
|
|
|
to me,
compare is looking at 2 objects and see if they are equal or not.
egalise a and b is a=b (change the value of a or b so that it is equal to the other value)
is it clear
|
|
|
|
|
ok, i get what's your problem then... you are trying to speak english with french words
don't say equalize but assign.
anyway, as you're using std::string s, just use the = operator for this, and == operator to compare their content.
std::string s1 = "Hello";
std::string s2 = "World";
ASSERT(s1 != s2);
s1 = s2;
ASSERT(s1 == s2);
|
|
|
|