Igor🇺🇦
Is there a data structure that holds N element and pushes older ones back when a new one is added, but never grows and just drop the oldest element when it gets full?
https://www.geeksforgeeks.org/lru-cache-implementation/ This one will delete elements that are not used for longest time
Anonymous
Can anyone help me … please dm !
Ömer Furkan
How can I learn standart C and C++ library usage? I'd like to implement system libraries on my projects but I couldn't find good source for using libraries
Anonymous
You don't need to. https://stackoverflow.com/questions/11529580/how-can-i-run-two-loops-simultaneously-c
Thank you sorry I think I pharases my question wrong. Can I show the output of two loops beside each other?
Anonymous
Ask here.
Bro it’s kind offff personal….
Anonymous
Thank you sorry I think I pharases my question wrong. Can I show the output of two loops beside each other?
If anyone can explain or any links to help? If trying to display output of two do while loops beside each other. As it's a race simulation so the results of them moving from position 1-60 and the action must be output for each runner. So I want to display the output of the two loops and their results beside each other
Anonymous
Okay thank you will read up on this
Anonymous
How can I learn standart C and C++ library usage? I'd like to implement system libraries on my projects but I couldn't find good source for using libraries
try to learn another language, C++ has many not popular language features, but if search popular features with words "str_replace c++" where str_replace = php function - The results will be find more faster.
Ömer Furkan
I don't know another language from C
Anonymous
any, python node etc...
Ömer Furkan
Just little bit
Ömer Furkan
I'd like to use <sys/*> libraries
Ömer Furkan
the main purpose of my request is controlling hardware with my project
Ömer Furkan
system calls to operating system
Ömer Furkan
low level application
Anonymous
🤷‍♀️
SALIHU
Hey guys, quick question
SALIHU
So if #define doesn't take up memory space, then why isn't it widely used in c++?
Puspam
Hey guys, quick question
Ask the question directly
Puspam
So if #define doesn't take up memory space, then why isn't it widely used in c++?
Because those are constants, so you can't change those values at runtime
SR27
string removeDups(string s) { vector<int> v (27,-1); string ans=""; for(int i=0; i<s.size(); i++) v[s[i]]++; for(int i=0; i<s.size(); i++) if( v[s[i]] != -1 ) { char ch = s[i]; ans.append(ch); v[s[i]] = -1; } return ans; }
Anonymous
Because those are constants, so you can't change those values at runtime
can't you just redefine them? like #define a 6 and then #define a 5
SR27
ans.append(ch); giving error for this can anyone help
SR27
Given a string without spaces, the task is to remove duplicates from it. Example 1: Input: S = "zvvo" Output: "zvo" Explanation: Only keep the first occurrence
Anonymous
No. They are constants
Mhm, I rarely use #define, so idk, let me test ut
Anonymous
works but throws a warning when compiling
Anonymous
ari@ari-arch ~ % vim a.cpp ari@ari-arch ~ % g++ a.cpp -o a a.cpp:6: warning: "a" redefined 6 | #define a 5 | a.cpp:3: note: this is the location of the previous definition 3 | #define a 6 | ari@ari-arch ~ % ./a a = 6 a = 5
Anonymous
#include <iostream> #define a 6 int main() { std::cout << "a = " << a << "\n"; #define a 5 std::cout << "a = " << a << "\n"; }
Anonymous
string removeDups(string s) { vector<int> v (27,-1); string ans=""; for(int i=0; i<s.size(); i++) v[s[i]]++; for(int i=0; i<s.size(); i++) if( v[s[i]] != -1 ) { char ch = s[i]; ans.append(ch); v[s[i]] = -1; } return ans; }
You are indexing the vector using s[i] which will be an ASCII value assuming that is the default encoding and wont be in the range 0 to 26. Your program exhibits Undefined Behavior.
SR27
i want to insert it to the string ans
Anonymous
so how should i correct it
v[s[i]-'a'] if all characters will be lowercase
SR27
dont know
Anonymous
dont know
What do you mean dont know? You said it is giving an error. What error is that?
SR27
rog.cpp:23:24: error: no matching function for call to std::__cxx11::basic_string<char>::append(char&) ans.append(ch);
SR27
no i think we cant give character as an argument to append
Anonymous
no i think we cant give character as an argument to append
Well then you know the issue already. Use ans+= ch; This is inefficient but. You should ideally be using stringstream
Anonymous
Hello everyone, I'm trying to design a domain-specific protocol for my software. Could you recommend any references?
Hanz
btw, can i macro a #define statement?
Hanz
?
like: #define redefine(a, val) #undef a; #define a val
Hanz
is this possible?
G
Which software is best for c programming in phone?
I have a git project that may help you
Anonymous
is this possible?
Idk. I think can't. Can you try it?
Hanz
lazy zzz
Anonymous
lazy zzz
Got it. The syntax of macro function is #define identifier(identifier-list) replacement-list new-line The # in replacement-list will be recognized as preprocessing-operator. The operator should followed by a macro parameter. So you can't use preprocessing directive in replacement-list
Eugene
/get cppbookguide
DEV 7
#include<iostream> using namespace std; int main(){ int n,r,result=0; cout<<"enter the number"<<endl; //let say 652 cin>>n; while(n!=0){ r=n%10; //r=652%10 =2 result=result*10+r; //result = 0*10+2 = 2 this while loop repeat n=n/10; // n=652/10 = 65 } cout<<result; if (n==result) { cout<<"palindrome"<<endl; } else { cout<<"not palindrome"<<endl; } return 0; }
DEV 7
ok
why I am only getting not palindrome as utput
Anonymous
why I am only getting not palindrome as utput
ah, okay, but please don't do that
Ravi
Store it somewhere, let say temp, then perform if temp==result, then else ....
Anonymous
Write a c program that will prompt allows a user to key in name and ages of five students then display names of student below 18 years ? Someone help out with this one
Anonymous
klimi
The program
what with it exactly?
Anonymous
what with it exactly?
Help me write the program
klimi
Help me write the program
okay, sure. what is the problem that is stopiing you?
Anonymous
okay, sure. what is the problem that is stopiing you?
Am a beginner have tried to figure out how to write it but it's not adding up
Puspam
There are a lot of mistakes.
Puspam
int y, c, age; cout << "Enter the current year: "; cin >> c; cout << "Enter your year of birth: "; cin >> y; age = c - y; cout << "Age: " << age;
💆‍♂️💆‍♂️💆‍♂️
*Age=c-y; *Count<<Age;
smene
Hi guys, I would like to assign a Keyboard Key, such as: L_SHIFT, to a callback, how could I do?
Anonymous
Hello, I have learned python and I want to learn c++ any recommendation?
Anonymous
I have just tow week, I don't have resource to follow and be good in c++, I don't know where to start.
Anonymous
I have just tow week, I don't have resource to follow and be good in c++, I don't know where to start.
Two weeks is enough. Pick a online tutorial or a little book to learn. It can be searched easily.
Anonymous
Two weeks is enough. Pick a online tutorial or a little book to learn. It can be searched easily.
If you know Is this a good playlist to learn or to have overview and then start? https://youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb