How to egalise two strings
-
Hello, I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work...use strcpy(st1, st2);
-
use strcpy(st1, st2);
-
Hello, I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work... -
Hello, I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work...s1 is CString then can use CompareNoCase Compare
-
s1 is CString then can use CompareNoCase Compare
-
Hello, I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work... -
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):sigh:
-
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):sigh:
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
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
mandanani wrote:
== operaotr compares not equalizes
then why does the code:
c1='aaa bbb ccc'; f1='aaa bbb ccc'; cout< _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]; char string2[255]; strcpy(string1,"Test"); strcpy(string2,"Test"); if (strcmp(string1,string2) == 0) cout << "Strings are equal"; else cout << "Strings are different";
Check the documentation of the functions on MSDN to be sure you understood correctly the concept.
Cédric Moonen Software developer
Charting control [v1.2] -
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
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
me know that you use std::string
How do you know that ??
Cédric Moonen Software developer
Charting control [v1.2] -
toxcct wrote:
me know that you use std::string
How do you know that ??
Cédric Moonen Software developer
Charting control [v1.2]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.
Jonathan Wilkes Darka[Xanya.net]
-
toxcct wrote:
me know that you use std::string
How do you know that ??
Cédric Moonen Software developer
Charting control [v1.2]because he asked a question related 2 posts below ;P check this[^]
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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.
Jonathan Wilkes Darka[Xanya.net]
I think the OP was using the == operator with char pointers and that's why it didn't work.
Cédric Moonen Software developer
Charting control [v1.2] -
because he asked a question related 2 posts below ;P check this[^]
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
If somebody is motivated to understand that, i have tried to regroup and order the programme. I hope you will help me.
#include #include using namespace std; #include #include #include #include #include int main() { // Openning the flow : fstream list; list.open("listfile.txt",ios::in); // Decalaration of the variables: char t; int i; string s1; string s2; string s3; string s4; string s5; string s6; string s7; string s8; string s9; string s10; string s11; //Getting the name of the files: getline(list,s1);cout<tm_mday <<"-" << date->tm_mon + 1 <<"-" << date->tm_year + 1900 << ".txt"; //Declaration of the variables: int a1=0; int a2=0; int a3=0; int a11=0; int a4=0; int a5=0; int a6=0; int a7=0; int a8=0; int a9=0; int a10=0; char c; char t1; char t2; char t3; char t11; char t4; char t5; char t6; char t7; char t8; char t9; char t10; char f; // Opening clippr´ flow: fstream clippr; clippr.open("clippr.txt",ios::in); // Opening the files´ flow : fstream fichier1; fichier1.open(s1.c_str(),ios::in); fstream fichier2; fichier2.open(s2.c_str(),ios::in); fstream fichier3; fichier3.open(s3.c_str(),ios::in); fstream fichier11; fichier11.open(s11.c_str(),ios::in); fstream fichier4; fichier4.open(s4.c_str(),ios::in); fstream fichier5; fichier5.open(s5.c_str(),ios::in); fstream fichier6; fichier6.open(s6.c_str(),ios::in); fstream fichier7; fichier7.open(s7.c_str(),ios::in); fstream fichier8; fichier8.open(s8.c_str(),ios::in); fstream fichier9; fichier9.open(s9.c_str(),ios::in); fstream fichier10; fichier10.open(s10.c_str(),ios::in); // Getting the file lines: string c1;string c2; string c3; string f1;string f2; string f3; getline(clippr,c1); getline(clippr,c1);cout<
-
Hello, I would like to compare two strings: i used:
if (s1==s2) {
I have no problem to compile, but even when s1=s2 it doesnt work... -
-