« first day (1895 days earlier)      last day (949 days later) » 

user14697742
6:27 AM
I had a question
 
user14697742
what can be the cause of c++ producing weird characters in string ouput?
 
missing null terminator
wrong encoding
reading some binary file and just outputting it
 
user14697742
I was implementing the shunting yard algorithm
 
user14697742
it works fine but for division operator is spits out a weird character or two
 
user14697742
c++ is weird
 
user14697742
6:39 AM
@PeterT ah thanks fixed it I was printing the wrong characters
 
8:02 AM
About `asio`:



To close a Tcp client, which one should be used, io_context.stop() or socket.close()? What aspects should be considered when making such a choice?

As far as I know, io_context is thread-safe whereas socket is not.

So, I can invoke io_context.stop() in any thread which may be different from the one that has called io_context.run(). But for socket.close(), I need to call io_context.post([=](){socket.stop()}) if socket object is called in a different thread(e.g. the said thread calls aiso::async_read(socket, ...)).
 
 
7 hours later…
3:08 PM
can anyone see an idea to tackle that? it isnt activity selection nor knapsack nor dp bitmasks?
 
user14697742
3:21 PM
when I forget a return statement, cpp prints at least a thousand weird unrecognizable characters
 
user14697742
I cant find this behavior in, say python or js
 
user14697742
what is the reason?
 
user14697742
what causes these weird characters
 
@Euler2 unmanaged memory and the ability to read uninitialized memory (it's still an error, but will not always be a compile-time error)
you should enable more warnings if the compiler didn't tell you about potential issues with such a program
 
user14697742
I may sound stupid
but does that thingy (the weird characters) have any sort of encryption-like thing? I have seen one or two similar encrypters (produce seemingly random characters)
 
user14697742
3:30 PM
I hate asking stupid questions ._.
 
not related, they just both happen to have integer values that map to characters you normally don't see
 
user14697742
okay thanks for telling
 
5:49 PM
hey @sehe just wanted to say thanks for the help so far - I still haven't decided on websocekts or BSON/MsgPack yet due to me having to fix the DNSBL on the firewall
 
 
1 hour later…
7:15 PM
Hi guys, I have a small question regarding isdigit. This is my code snippet, I am trying to store a number into a vector if it is indeed a double/int but if not then I want to break. However, the if statement is breaking out of the while even tho a number is entered. Why is this?
while (true)
{
cout << "Enter a number to be stored in the vector(or alphabet to terminate):\n";
cin >> val;

if (isdigit(val))
{
vect.push_back(val);

}

else {
break;
}
}
 
@Electrical_engineer_student isdigit just checks a single character value, if you enter some fractional number with a dot. Then the period will break that loop (i.e. 12.34 will break after the 2)
and if you just "also accept '.' " then you'll run into something like 1.32.456.77
 
@PeterT why? I tried using just integers like 12 but still it breaks(as in the value does not get pushed back)
 
what is the type of "val"? It's just a char right?
 
oh no sorry val is a double
 
well then isdigit makes no sense, that's for processing single ascii character values
 
7:25 PM
no but I want the while loop to terminate if a non-number is entered?
actually never mind I fixed it now using a different type of if statement
is it possible to have a void function inside std::format?
for example
cout << format("Vector size is '{}'.It contains {}", count,print(vect));
 
I assume you mean that your "print" function just prints to stdout instead of returning a string value?
In that case, no, that code doesn't make sense
you can't magically backtrack the side-effects of a function from the "void" it returns
 
print is this
void print(vector<double>& vect)
{
for (auto i : vect)
cout << i << endl;
}
 
yeah, and that will be executed before format is ever called
all the arguments are resolved before a function is called
 
so how can one print the entire vector? it can't be done in std::format, should I just call it by itself
 
just calling it by yourself is the easiest way, you can also write a custom formatter for the vector type, seems overkill to me for a small program though
 
7:35 PM
ok thanks man
 
8:28 PM
Hi, how can one find all occurrences of a given number in a vector, I know iterator can be used from the #include<algorithm> module but how can you find the index of all instances of that value you are looking for?
 
 
3 hours later…
11:36 PM
@Electrical_engineer_student std::find in a loop, or just a loop of your own: for (int i=0;i<foo.size(); i++) if (foo[i] == value) results.push_back(i);
 

« first day (1895 days earlier)      last day (949 days later) »