How to egalise two strings
-
-
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<
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
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 :~
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 :~
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 :~
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
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, ragazzi, ora, rilassatevi...:-D
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
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
uhh, sorry, i don't understand much italian ! lol
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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 :doh:
ok, i get what's your problem then... you are trying to speak english with french words ;P 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); // the objects contain different strings
s1 = s2; //Assign s2 content into s1
ASSERT(s1 == s2); // the objects contain same strings
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
ok, i get what's your problem then... you are trying to speak english with french words ;P 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); // the objects contain different strings
s1 = s2; //Assign s2 content into s1
ASSERT(s1 == s2); // the objects contain same strings
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
OK, just to see if i have caught what you said: I should use == to compare if string s1 has the same content with string s2. That´s it? Because I already have tried that and it doesn´t work...:((
-
OK, just to see if i have caught what you said: I should use == to compare if string s1 has the same content with string s2. That´s it? Because I already have tried that and it doesn´t work...:((
garfaoui wrote:
I should use == to compare if string s1 has the same content with string s2. That´s it?
exactly. but be careful, the operator must be the overload of std::string class. in the expression
s1 == s2
, if s1 is of type std::string, the code actually means to the compilers1.operator==(s2)
(calling then the functionbool std::string::operator==(const std::string&)
). but if s1 is a basic C-Style string (a char* basically), the compiler will try to compare the addresses, not the string contents... the context is exactly the same while using theoperator !=
. so, can you please post a relevant (but small) piece of code which can reproduce the error ? also, specify to us the type of all the variables used, and which error you get (if it is a compiler error, linker error, or run-time error), and its message.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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... -
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. :)
-
Francais et en stage au Portugal ?
Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]
-
Te laisse pas impressioner par Tox, il est dur, mais très très fort. ;P
Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]
-
Ne t´inquète pas! En tout cas il m´a bien aidé! C´est par rapport au repertoire de l´executable que tu as vu que j´étais au Portugal?
non, par rapport a ton profil ^^ @Régis, merci pr la petite note d'humour... "il est tres tres fort", c'est a double tranchant ca ;P
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]