Patrick
How can I use std::string in GDB?
Guy
How can I use std::string in GDB?
What do you mean use std::string in gdb? you can read strings with x/s <string_ptr>
Patrick
Guy
I don't think it's a thing
Patrick
Alright. Well, I have another issue actually
Patrick
in GDB after this line: void* sPtr = new std::string("hello"); Doing x/s sPtr Results in garbage. I'd like to declare a std::string on the heap, referenced in a void*, but it isn't working.
Guy
it's because std::string encapsulates many other things (http://www.cplusplus.com/reference/string/string/ )
Guy
when you use x/s sPtr you actually just try to read characters from that address until you reach a nullbyte. https://stackoverflow.com/questions/6776961/how-to-inspect-stdstring-in-gdb-with-no-source-code
Patrick
So I should use c_str
Patrick
but I can't cast my void* to std::string in GDB
Guy
anyways google it, I'm sure many others have encountered this specific issues
Patrick
but I can't cast my void* to std::string in GDB
I did try searching how to include std::string in GDB to no avail
︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎ ︎
@codingmeme
Appiah Kumah
hello friends, please i need your help to solve a c++ problem. i have try but not getting it.
Appiah Kumah
questions A company want to transmit data over the telephone but is concerned that its phones could be tapped. All of the data are transmitted as two-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Your program should read a two-digit integer and encrypt it as follows: Replace each by ( the digit plus 7) and modulus 10). Then, swap the first digit with the second and print out the encrypted integer.
Harsh
Thank you very much.
Welcome mate 👊🏿
Appiah Kumah
Welcome mate 👊🏿
Please, am using c++ to code it. Please, can u guide me..please?
Harsh
Please, am using c++ to code it. Please, can u guide me..please?
Sure, but I already told you what to do. 1. Read a number from stdin 2. Get one's place and tens place by above method 3. Do the required operations 4. Add up 5. Print on screen
Appiah Kumah
Ok...thanks
Appiah Kumah
What about this? Write a program that displays the recommended weight in kilograms, given the user's age and height in centimeters. The formula for calculating the recommended weight is: Recommended=(height-100+ age%10) * 0.90.
Appiah Kumah
Should I give the user my own figure or ask for it, please.
Indolent
pastebin.com/hBs37hvL
Indolent
Can anyone explain to me what's happening in this code?
Appiah Kumah
Ask for it
ok thanks
Indolent
pastebin.com/hBs37hvL
What is the for each loop doing? And how do you access the pair vector?
Indolent
Anyone?
Artöm
What is the for each loop doing? And how do you access the pair vector?
For each iterates over a collection and processes each element
Artöm
Theres no pair in that code
Anonymous
If two sub classes with some same functions is there a way to prevent code duplication?
Artöm
Make base class inbetween, move common functions there
Som
#include<iostream> using namespace std;   class bank { private:      float p;      float r;      float t;      float si;      float amount;   public:     void read ( )           {                  cout <<" Enter Principle Amount :: ";                  cin>>p ;                  cout<<"\n Enter Rate of Interest :: ";                  cin>>r;                  cout <<"\n Enter Number of years :: ";                  cin>>t;                    si= (p *r*t) /100;                  amount = si + p;             }       void show( )          {                 cout<<"\n Entered Details are :: \n";                 cout<<"\n Principle Amount: "<<p;                 cout <<"\n\n Rate of Interest: "<<r;                 cout <<"\n\n Number of years: "<<t;                 cout <<"\n\n Interest : "<<si;                 cout <<"\n\n Total Amount : "<<amount<<"\n";          } };     int main () {     bank b ;       b.read ( );     b.show ( );       return 0; } Is this correct?
Alex
it work only in this example
provide example which does not work
Anonymous
Can someone explain why is line 22 wrong?
Artöm
Why do you think its wrong?
Anonymous
Oh thats cause no operator matches the operands 👍🏼
Alex
add operator or use function in B class for comparison
Artöm
Show full code
Artöm
I see < above and wonder if it is related
Alex
Can someone explain why is line 22 wrong?
you can use min function from std lib
Artöm
mark operator< as const
Artöm
Or make it a free function
Anonymous
👍🏼👍🏼
Alex
free function is not the option, cause he uses n field
Artöm
He can make it friend
Alex
I don`t think its good idea. because of encapsulation violation
Artöm
Friend for comparison operators is always a good idea
Artöm
Hidden friend is even better
Alex
what are pros for this approach?
Alex
what is hidden friend?
Artöm
what are pros for this approach?
It works well with implicit conversion constructors
Artöm
what is hidden friend?
Read P1601 paper
Artöm
It is a function which is only callable via adl
Alex
I can`t understand your idea. please refer to std lib. operator functions are member of a class or free function. no friends
Alex
except when it have to be friend, like operator«
Artöm
Eg these https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp are required to be implemented as hidden friends
Artöm
To avoid unwanted overload candidates
Alex
Eg these https://en.cppreference.com/w/cpp/filesystem/path/operator_cmp are required to be implemented as hidden friends
why do you think they are friend? they can be implemented using methods of path class
Artöm
why do you think they are friend? they can be implemented using methods of path class
No they are not, "/text" == some_path should be valid
Anonymous
Is there a good website that explains about functor?
Alex
functor is everything which can be called using ()
Chirag
/get cbook
Anonymous
/get
Anonymous
Ok
Anonymous
Chirag
/get best-book
Chirag
/get india
Wisenky
Guys I have a question , Is working on machine learning or something like that is really hard on cpp ?
Wisenky
Im glad to hear that
Wisenky
Lol
Wisenky
Where can I start to learn these facts for cpp , most of the documents based python
Francisco
Guys I have a question , Is working on machine learning or something like that is really hard on cpp ?
Machine learning is hard in C++, but it's fast. For personal projects, just use Python. You'll avoid a lot of headaches
Wisenky
I'm student so asking this and thanks a lot guys