klimi
I am using windows, i've red about conio.h, is it the only way to do it?
i don't really know... i don't use windows at all... maybe something with the Win32 API
klimi
how it can be solved in linux or mac?
well for linux if you run X server you can just use the X api to get all the input that Xserver recieves
klimi
(XEvent)
Ehsan
I am using windows, i've red about conio.h, is it the only way to do it?
https://stackoverflow.com/questions/1437158/c-win32-keyboard-events
Anonymous
well for linux if you run X server you can just use the X api to get all the input that Xserver recieves
This behavior is now deprecated. Users should now listen to such events on dbus. The older events would still be published but any code that you write now or in future should use D-Bus
Anonymous
I see.. Thanks for letting me know... I am not sure how I feel about dbus tho...
Actually now Wayland is also gaining a strong foothold. But the community is actually divided on what to use.
klimi
yeah... but i haven't really did anything on the wayland so... ¯\_(ツ)_/¯
klimi
well that completely breaks my system but nice try
Unus
I want a C programming language app
Unus
What's the best
Nameful
Like one for programming on your phone?
Nameful
Or just learning programming
Anonymous
On app no need special test edit etc just download app and run your code also you learn c++ step by step free of cost with 2thousand examples
Azhar
I want addition of max and min inthis
Azhar
Why my code deleted
Anonymous
Why my code deleted
Because we already told you that you have to use sites like pastebin.com to post your code. This reduces clutter
Azhar
Whats this dude
Anonymous
Everyone posting
That should also be deleted. Did you read the rules when you joined?
Anonymous
Can any one help teach me C++ from scratch 🙏🏿
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
Can any one help teach me C++ from scratch 🙏🏿
Bro that’s not possible This is not a school bro Even I don’t think schools teach everything. Best thing to do is to learn on your own And I’ll recommend you start from YouTube. There’re so many courses on YouTube! Pick 1 and or 2 of them and you should be able to grasp at least the basics
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
Can any one help teach me C++ from scratch 🙏🏿
I said all that because I’m also a beginner and that’s how i started. Don’t think depending on someone to teach you everything is the best way to go
Otumian
Can any one help teach me C++ from scratch 🙏🏿
Yeah.. check this book.. it taught me some cpp.. ds malik c++ programming 8th edition solution. When you run into a problem then you google or ask here.. a lot of guys here are also learning c++ and are willing to assist. There are guys here that can talk in c++ so no worries, get yourself coding on your own.
Golden Age Of
Hello, how can i listen to keyboard events globaly, not from the console in C?
windows.h may be, but I'm not sure it's available in C
V01D
If we're talking about a cyber security type of use it has the upside of evading av scans once injected. Downside is that you'd need a good plan to SE your target into installing a kernel module (assuming this is legal/you obtained permission to do so)
V01D
At least I think it evades av scans, I could be wrong. Please correct me if that's the case
Yorhane
Good night people. It's a layman's question. Can I see information about an already open program?. Right after seeing the real-time information
Ian
Does anyone know how to simulate multithreading and concurrency using either c or c++?
Sujay_Adoor
Hi
Peace
is it a good way to print array elements ? Well I am getting the right output. if some optimization , please tell void printArr(int *arr,int *n){ for(int i=0;i<*n;++i){ cout<<arr[i]<<endl; } }
Peace
Why would you use n as pointer ?
for avoiding copy of n
\Device\NUL
for avoiding copy of n
avoiding copy ?
Peace
avoiding copy ?
yes. This pointer is pointing to n which is declared in main function . so any changes happening with this pointer will affect the value of n of main also. If we don't use pointer , it will work also.
Peace
Did the n var really changed inside the loop ?
no. I am using as a limit of for loop
\Device\NUL
no. I am using as a limit of for loop
So why would you use n as pointer ?
\Device\NUL
Just to make sure, make the n var is const if doesn't change
Peace
okay.
Ammar
for avoiding copy of n
This reason does not make any sense, you have an extra dereference for passing a pointer. Copying an integer is much cheaper than copying a pointer + dereference. So, instead of this one: void printArr(int *arr,int *n){ for(int i=0;i<*n;++i){ cout<<arr[i]<<endl; } } It would be much better to use this: void printArr(const int *arr, int n) { for (int i = 0; i < n; ++i) cout << arr[i] << endl; } Avoiding copy is good when you pass a large data like a struct that contains many fields, or an array (like your first argument, it *does make sense*, but the second argument does not have to be a pointer).
Ammar
Adding const to make sure it's value doesn't change ~ Rust mutability
Good advice, the first argument could've been marked as const because the function doesn't change the value pointed by that pointer. Applied, thanks!
YVEF
hi Guys. have a question. I have some .dll which exports some function. I want to call it from my project. I found some solution like LoadLibrary explicit, and using offsets found my export func. but is there any one better solution? thanks
john
hello im having problems adding cin in my class's and objects in c++
Pavel
hello im having problems adding cin in my class's and objects in c++
Can you explain what kind of problem you have and some details about it (e.g. code example, explanation of what behaviour you get from this code, and what behaviour you expect)
Ammar
On Wed, 17 November 2021 at 19:57:23 GMT+07, 【=◈︿◈=】 wrote: > > the first argument could've been marked as const > > Bruh, the first argument is const but the second is not It seems you misunderstand. I fully agree with your comment, go read and review my message, I have applied your suggestion several hours ago.
Ammar
The second could be const too, the loop is using increment, not decrement
Not strictly necessary, the pointer part *does finely apply* the const (fully agree with that, so we can pass .rodata pointer to it). For the second argument, I just don't want to use it all over the place.
Ammar
B-but i have deleted my message
Ah, your message still lives on my Telegram client, you are better off editing it :)
Ammar
B-but i have deleted my message
I just want to emphasize the reason of why the second argument is not strictly necessary const. Here is the example: void printArr_aaa(const int *arr, int n); void printArr_bbb(const int *arr, const int n); void fx(void) { const int n = 4; const int arr[] = {1, 2, 3, 4}; printArr_aaa(arr, n); printArr_bbb(arr, n); } Both calls work just fine. But... void printArr_aaa(const int *arr, int n); void printArr_bbb(int *arr, int n); void fx(void) { const int n = 4; const int arr[] = {1, 2, 3, 4}; printArr_aaa(arr, n); // Error, can't accept (const int *) printArr_bbb(arr, n); } So marking the second argument as const does not really change the situation. That's why it's not strictly necessary.
数学の恋人
struct SomeStruct { static constexpr size_t MAX = 1024 * 64; std::array<type::byte, MAX> data; } __attribute__((aligned(MAX))); what does that __attribute__((aligned(MAX))) means here? I kind of have fair idea, but why is that needed?
Ammar
struct SomeStruct { static constexpr size_t MAX = 1024 * 64; std::array<type::byte, MAX> data; } __attribute__((aligned(MAX))); what does that __attribute__((aligned(MAX))) means here? I kind of have fair idea, but why is that needed?
It instructs the compiler to place the struct at address multiple of MAX. In your case, it's multiple of 1024 * 64. I don't know why do you need that, it's even more than just a widely used page size, which is often only 4096. This seems to over-align for me. Not sure what's your need. As far as I can tell, there are several reasons to use this attribute: 1) You need aligned move for vector operations, like (x86-64 specific): - {v,}movdqa w.r.t. xmm register (need 16-byte aligned). - vmovdqa w.r.t. ymm register (need 32-byte aligned). - vmovdqa64 w.r.t. zmm register (need 64-byte aligned). [ There are more, but at least these cover the generic case. ] If the source or destination memory address is not multiple of the specified above, your program will get #GP exception, so for userspace will just be segmentation fault. 2) You need to create your own allocator and for some reason you need to guarantee that the user gets the minimum alignment for the specific case. Like implementing malloc(). For example: https://lore.kernel.org/io-uring/20211011064927.444704-1-ammar.faizi@students.amikom.ac.id/T/ 3) You want to align your struct to avoid false sharing in SMP system (performance wise). In the Linux kernel, we have a macro that yields something like that, like ____cacheline_aligned and ____cacheline_aligned_in_smp. Link: https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/include/linux/cache.h#L40-L50 4) Add yourself... there are a lot of reasons...
Jagadeesh
//Multiples of 3 and 5 #include<stdio.h> #include<math.h> int ap(int x) { int result =floor(x*(x+1)/2); return result; } int main(){ int n,a,b,c; scanf("%d",&n); while(n!=0){ int nu; scanf("%d",&nu); nu-=1; a=floor(nu/3); b=floor(nu/5); c=floor(nu/15); printf("%d\n",3*ap(a)+5*ap(b)-15*ap(c)); n--; } }
Jagadeesh
can anyone help me to find the error
Puspam
//Multiples of 3 and 5 #include<stdio.h> #include<math.h> int ap(int x) { int result =floor(x*(x+1)/2); return result; } int main(){ int n,a,b,c; scanf("%d",&n); while(n!=0){ int nu; scanf("%d",&nu); nu-=1; a=floor(nu/3); b=floor(nu/5); c=floor(nu/15); printf("%d\n",3*ap(a)+5*ap(b)-15*ap(c)); n--; } }
First of all, you don't need to floor the result of x*(x+1)/2 since, if x is odd then x+1 will be even & vice-versa, so one of the numbers will be even. And, if any number (odd/even) multiplied by an even number, the result will always be even. Even numbers are exactly divided by 2, so there won't be any fraction.
✨Justina
plz help me,can anyone know were the error?
Puspam
any other error
No. It's running fine
Puspam
You have declared x & y both as float & string.
✨Justina
You have declared x & y both as float & string.
Oh which means I need to explain the x & y ?
Puspam
Oh which means I need to explain the x & y ?
No. See, you have declared float x, y Also, string x, string y. You need to change those names.
Anton
Hi everyone! I declare following arrays in two different programms. A) static arr[x] B) static arr = malloc(x) Few question regarding memory management. 1) Arrays A and B both have static storage duration? 2) In which case it considers a leak if I don't free the array at programm exit?
✨Justina
#include <iostream> #include <iomanip> #include <cmath> #include <string> using namespace std; int main() { char vip; int acc; float x, y, z, cbalance; string x, y; cout << "Enter account number ( -1 to end): "; cin >> acc; if(x)= "\nCredit Limit Exceeded."; else (y) = "\nCredit Limit Not Exceeded.";
✨Justina
correct uh?
Hamza
How to made table of shopping item with price in c++