Nicola
[Error] no match for 'operator=' (operand types are 'std::string {aka std::basic_string<char>}' and 'void')
Nicola
I wrote it, I was just wrong to read libraries
Anonymous
compiles fine for me now
Anonymous
#include <iostream> #include <string> #include <time.h> #include <windows.h> #include <stdio.h> #include <algorithm> using namespace std; //string PBOX1(string s) { // string s1; // s1 = random_shuffle(s.begin(), s.end()); // return s1; //} int main(int argc, char** argv) { string s1; cin >> s1; cout << s1; //string s2 = PBOX1(s1); string s2 = s1; random_shuffle(s2.begin(), s2.end()); cout << endl << s2; return 0; }
Anonymous
> [Error] no match for 'operator=' (operand types are 'std::string {aka std::basic_string<char>}' and 'void') Because random_shuffle() return void
Anonymous
does it work for you now?
Nicola
Yes but even if I compile again random_shuffle always presents me the same exchange
Anonymous
Anonymous
not for me
Anonymous
s1 is the input and s2 the shuffled string
Nicola
Yes but s2 is always 9203168457
Nicola
even if you re-run, the same number should come out
Anonymous
is your input the same?
Anonymous
:)
Anonymous
this is a side effect of the "random" numbers. you have to reset you pseudo random number generator, so you will get another output with the same input.
Anonymous
some functions provide an parameter wich is called seed, that seed number (usually your local time) is the magic number to recallibrate the pseudo random number generator
Anonymous
call srand(time(0)); before you use random_shuffle()
Anonymous
that should do it
Anonymous
https://stackoverflow.com/questions/14221763/stdrandom-shuffle-produces-same-result-each-time
Nicola
Thanks, I'm trying now
Anonymous
NP, I tried it on my machine. Worked pretty well
Anonymous
If you are interested in <algorithm>, I can recommend you this video. A very good one from CppCon https://www.youtube.com/watch?v=2olsGf6JIkU
Anonymous
This guy in general
Anonymous
@Shelly: Yeah, indeed. I'm a fan after this talk too. Andrei Alexandrescu has some very entertaining and cool videos too.
Nicola
I followed your advice but the exchange is always the same as the previous string, that is the XOR
Nicola
Anonymous
ähm... do you want to shuffle the characters of a string or the bits of a word. i am a bit confused right now
Anonymous
shuffle() or random_shuffle() do not shuffle the bits
Anonymous
only the single elements within a container/string
Nicola
only the single elements within a container/string
I know but it can shuffle the position (the index)
Nicola
If I use random_shuffle in the main, it work correctly
Nicola
if I use it in one method it doesn't work anything
Anonymous
can you show me your current code?
Nicola
yes
Nicola
void PBOX1(string s){ srand (time(NULL)); random_shuffle(s.begin(),s.end()); } int main(int argc, char** argv) { string s4; cout<<"WORD : "; cin>>s4; PBOX1(s4); //doesn't work random_shuffle(s4.begin(),s4.end()); //work correctly cout<<"SHUFFLE : "<<s4; return 0; }
Anonymous
I see
Anonymous
void PBOX1(string s){
Anonymous
you pass the string as a copy, so you shuffle the copy, not the original
Anonymous
after you leave the function, the modification on the copy gets lost
Anonymous
try this one
Anonymous
Not void PBOX1(string s){ but void PBOX1(string &s){
Anonymous
this way, you pass the parameter as a reference and you are going to modify the original
Anonymous
exactly, buddy :)
Nicola
exact?
Anonymous
Anonymous
whaaaaaaaa !!!
Anonymous
:D
Anonymous
You made a pointer, not a reference ;)
Nicola
Ahhh sorry
Anonymous
Try to make a reference with an ampercent &
Anonymous
;)
Anonymous
That trigger 😆But same here
Anonymous
@Shelly :D :D :D
Nicola
Thanks a lot
Anonymous
Easy, buddy
BinaryByter
You made a pointer, not a reference ;)
he didnt get the reference
BinaryByter
youll have to give him a small pointer
Anonymous
yeah, perhaps
Dima
Lol
Nicola
yeah, perhaps
Viktor is there a way to get the initial order back?
Anonymous
@NICOOH : Only if you make a copy before you make the shuffle. The is (unfortunatelly) no way to do a reverse shuffle
Sanji
How to use termux
Anonymous
How to use termux
Only god knows
Anonymous
Only god knows
Its easy for linux working people..
Sanji
Can somebody please help me to do c program in termux
Anonymous
Did some of corutils have been written in c++?
Pete
Does anyone have experience with raspberry pis
Anonymous
What is purpose of array in c language friend s any tell little bit about that
Anonymous
??
S.
Purpose is a big question
Anonymous
Pls Tel small why using array
S.
Like you have 10 variables, int a,b,c,d,e,f,g,h,i,j;
Anonymous
Purpose is a big question
Thk u for interst me
S.
sometimes you just wanna group them up. int a[10];
Anonymous
hi
Anonymous
hello