Shaonianan
Danya🔥
Shaonianan
std::shared_ptr<Stock> get(const string &key)
{
std::shared_ptr<Stock> pStock;
muduo::MutexLockGuard lock(mutex_);
std::weak_ptr<Stock> &wkStock = stocks_[key];
pStock = wkStock.lock();
if (!pStock)
{
pStock.reset(new Stock(key),
std::bind(&StockFactory::weakDeleteCallback,
std::weak_ptr<StockFactory>(shared_from_this()),
_1));
wkStock = pStock;
}
return pStock;
}
Shaonianan
static void weakDeleteCallback(const std::weak_ptr<StockFactory> &wkFactory,
Stock *stock)
{
printf("weakDeleteStock[%p]\n", stock);
std::shared_ptr<StockFactory> factory(wkFactory.lock());
if (factory)
{
printf("factory live.\n");
factory->removeStock(stock);
}
else
{
printf("factory died.\n");
}
delete stock; // sorry, I lied
}
Shaonianan
Danya🔥
Danya🔥
Shaonianan
it bind a point to fuction,the function take two parameter.
Shaonianan
Danya🔥
Read my message carefully, the compiler error and you can also ask ChatGPT
Shaonianan
You don't understand this grammar either, thank you too. I have seen the reason for the compilation error and asked chatgpt, but I couldn't find it.
Kevin
Has anyone done the 4 sum problem in c++?
Kevin
Kevin
Anyone
Danya🔥
Anyone
/warn not able to read
Andre
#markdown
Andre
How can I do the same for \b?
char c;
while(( c = getchar()) != '\n')
{
if(c == '\t')
{
putchar('\\');
putchar('t');
}
}
I mean i know that if i write
printf("a\bb");
The output will be b.
But how in I insert a sequence of chars like "ahaggaja" to have printing \b..
Doing an exercise from a book
Andre
If you write a tab print \t, if you write a \ print \\, if you write a backslash char print \b. Im going nuts with this
Ziky
Ziky
maybe chack this https://stackoverflow.com/questions/6792812/the-backspace-escape-character-b-unexpected-behavior
Ziky
\b is backspace not backslash
Andre
I know i got it right... the full program replaces everything .. what im asking is how can actually see a replacement of backspace with \b
Andre
I dont know what char to write and press enter to convert and output \b... i think the purpose of the exercise is to make u understand that some char are for selextion and other for formstting
Ziky
Huh I doubt you can get backspace char from terminal as input to your app.
Maverick
Sorry to ask this question I know this is not valid question to ask here.. But since currently I only know c++ so can anyone here suggest me any YouTube channel where I can find some problem solving tools and tips using in c++ in context of competitive programming
Andre
Check errichto channel. what tools...debugger
Abhay
hi
klimi
hi
please read the rules, thank you
Elfa Metesar
Stop bothering me in pm people. i lost count of how many are texting me stuff like hi, sending me hello or kissing emojies in pm from this group
klimi
Elfa Metesar
Andre
```
Chat Boss
Andre sent a huge message, it has been re-uploaded as a file
Two questions, Why do i have to put to IF instead of ELSE_IF in this case ? and if i put two IF ..
Andre
sorry trying to use the snippets from pc and its working bad.
Andre
the program its simple, it should just count how long is a word. There are plenty approaches to this, i just want to count the characters and if i hit a white char then i store in an array at correct index the nr of occurances of that lenght. Yet it seems to not work. and i think the error is in IFs.
klimi
Andre
ive put two ||
Andre
if(c != '\n' c != '\t' c != ' ') and else if(c == '\n' c == '\t' c == ' ')
Andre
here it doesnt show it .. .
Andre
you dont see them because of telegram, dont know why it doesnt copy right let me retry
Chat Boss
Andre sent a code, it has been re-uploaded as a file
Danya🔥
Andre
Dont know what I did wrong, I've just copy pasted from code blocks into ''' '''. But got wrong the closure I think. Anyway, the last message, is correct, I've checked it.
Elfa Metesar
Elfa Metesar
it should be &&, putting || there is a logical mistake because it will always return true
Andre
... how can a single char can be equal to 3 different chars at the same time
Andre
it has to be an OR not an AND
Elfa Metesar
it's not ==, it is !=. a single char can be not equal in 3 different comparisons
Elfa Metesar
if(c != '\n' && c != '\t' && c != ' ')
{
char_counter++;
}
else {
word_length[char_counter] = word_length[char_counter] + 1;
printf("%d\n", char_counter);
char_counter = 0;
}
Andre
is the same thing .... if c is not equal to al 3 or not equal to all of them in the end u test .. thats not the error.
Elfa Metesar
Andre
I dont know what to say. Its a simple program, I know how to do it, and in this case putting an OR or using AND is the same thing. But in my case after i compile and give input whatever it doesnt work.
Elfa Metesar
show the code after modifications
Chat Boss
Andre sent a code, it has been re-uploaded as a file
Andre
prints always from 1st IF.
Andre
i've noticed that with && it print 3 if i give in input "ASD" but with OR it prints 4. why the fk .
Elfa Metesar
prints always from 1st IF.
the second if shouldn't have &&, it should have || . only the first if is with &&. you don't need the second if either, you can just put else there
Andre
now it works, still i dont get why I need to put an && in the 1st one instead of an || ... Im just reading a char at a once, so i test that char and if is not equal the 1st the i check the second and do the same with the 3rd. If i use an and if is not equal it should go out.
Andre
without testing furter.
Elfa Metesar
you're using && in the first if because you're saying, hey if c isn't equal to \n AND isn't equal to \t AND isn't equal to ' ', then increase the counter
Elfa Metesar
basically saying if c doesn't match all those 3 chars
Andre
... whats the difference between that and saying c is not equal to this or that. in the end in the 1st case with and you need 3 trues, in or case you just need one, and they are going to be false.
Andre
i dont get it.
Andre
let say it differently.You enter "ASD\n" so you test A S D 3 times and they all evaluate to false.
Elfa Metesar
because when you say or, it only checks for the first condition. let's say c = '\t'. you compared it in the first condition with \n. it is not equal right? so it will discard the rest of the conditions and increase the counter because it already returned true from the first condition.
Elfa Metesar
because c != \n, = true
Andre
.... the problem is entering the second one
Andre
the program doesnt enter the second IF not the 1st
Andre
and the OR evaluates to TRUE because c == \n
Andre
thats why i dont understand.
Andre
anyway doesnt matter i will get it.
Elfa Metesar
that's what im saying, it already evaluates true from the first if check by not being equal to \n
Elfa Metesar
so why should it check for the second if
Elfa Metesar
Elfa Metesar
you just hit enter right?
Andre
Of course.
Andre
i've got it the 1st loop has to be with &&. Because when I hit enter \n is false (it's not !=) but the other 2 conditions are still true. So i get stuck in 1st loop.
Andre
thanks