Joe
ok no probs i think it was someone else in here then. I`m just sending strings from a server to a client and i used "ostringstream oss" . so after copying the string into oss (oss << "value of string" << "\n" i sent it over a socket using something like send(socket, oss.str().c_str(), ... ) something like that but i can not remember the whole send function and couldn`t find it yet
klimi
ye
klimi
i had tons of tabs
klimi
i hope the purchase cart is still saved
BinaryByter
BinaryByter
you convert the ostream to a string and then the string to a c-string
Anonymous
Hello .
I just want to ask that as we know that void pointer is type independent pointer..
Means we can point memory of any data type with void pointer..than why we don't use void pointer always in every scenario..?
Why we declare int pointer, char pointer etc as separately..we can all that stuff with void pointer also..
Can anyone please answer..?
klimi
BinaryByter
BinaryByter
you can typecast all pointers
BinaryByter
C++ is pointer sensitive
Joe
BinaryByter
but a pointer type has something more than just a pointer
BinaryByter
it contains information at compile time about how to interpet a memory location
Joe
BinaryByter
sure :D
BinaryByter
have fun
Anonymous
Anonymous
I use it in C++. Not C
BinaryByter
yea, in C++ you should use templates for such a job
BinaryByter
template <class T>
void myFunction (T& obj) {
std::cout « obj;
}
BinaryByter
for example
Anonymous
What about
Anonymous
If I use as
Joe
@linuxer4fun does that make sense?
send(new_socket , oss.str().c_str(), strlen(oss.str().c_str()) , 0 );
BinaryByter
oss.str().size()
BinaryByter
strlen is slow
BinaryByter
+ store the string beforehand
BinaryByter
makes you save one call to .str()
Anonymous
Int a=5
Void *ptr =&a;
Int *p=static_cast <int>(ptr);
Cout<< *p;
BinaryByter
i don't quite get why you would do that?
BinaryByter
also, its a reinterpret_cast
BinaryByter
is it?
Anonymous
I have to type cast void pointer to int pointer..
BinaryByter
yes
BinaryByter
but its a reinterpret_cast
Joe
👌🏼
Anonymous
Anonymous
Bcoz I'm printing value..not address
BinaryByter
well first of all, in modern C++ you only seldomly need pointers
BinaryByter
second of all, void pointers are something you should avoid like you would avoid rats
BinaryByter
in C++ theres just no reason to use void pointers
Anonymous
Okey..
Thanks bro
Anonymous
👍
Joe
+ store the string beforehand
but when doing oss << "string"; and then calling the send function that´s already the fastest isn`t it?
BinaryByter
BinaryByter
if you could avoid the stream and instead just use a string, that would be better
Joe
I once tried it this way but didn`t get it to work.. as of now the stream is relatively fast (but faster is always better ofc). I`m plotting a graph (absorption spectrum) from sensor data and now one full spectrum arrives approx every 200ms. do you think the other option is much faster?
🆂🄾🅼
sir plz do a program in cppb using classb of matrix transpose
🆂🄾🅼
plz sir help fats
🆂🄾🅼
I ve to submit my project tommorow
Anonymous
Copy it from ur book
Stefan
Language:
cpp
Source:
#include <stdio.h>
class Slot {
public: ~Slot() {
printf("Goodbye world!");
}
};
int main(void) {
Slot ins;
return 0;
}
Result:
Goodbye world!
Note:
cplusplus_gcc assumed, other valid options are cplusplus_clang, visual_cplusplus, you can be more specific next time.
Stefan
now that's a pretty good bot
🆂🄾🅼
klimi
🆂🄾🅼
Stefan
hmm its too long
BinaryByter
Joe
how does the data arrive?
I`m reading it via TCP-listen-function on Labview. there it deconstructs the string and plots it.
BinaryByter
sure but how is the string encoded?
BinaryByter
actually it doesnt even matter
Joe
ok :D
BinaryByter
just do this:
BinaryByter
string +=
BinaryByter
actually
BinaryByter
ostream« might not be slower
Joe
string +=
can I add strings with math operators? i thought I always have to use something like strcpy
Anonymous
Anonymous
in C you cannot
Joe
daaamn ok I`m coming from C that makes sense
Anonymous
Anonymous
strcat is better implemented
BinaryByter
BinaryByter
std::string is NOT made to be used with C-style functions
Anonymous