Anonymous
Its a task
Dr
So basically I have to find, these so called runs in a string. But how to separate them?
Well, I don't know for sure, but I would use Brute force and append each character to new string and will check if current character is alphabetical as prev or numeric and so on......😬
@omar
I see. Thanks. Have to try
Anonymous
What is the reason for this code not to compile? Why does it try to resolve std::to_string call before the concrete type is known? Is there a way to prevent that (like we do with .template function calls)? https://ideone.com/224VeQ
Extending std namespace like you have done is Undefined Behavior. There are limited cases where extensions to std namespace is allowed. to_string is not one of those cases. You must do something like this instead. https://ideone.com/FdtzVz It doesn't try to resolve std::to_string call before the concrete type is known btw.
Anonymous
This is the code: int**i, i= malloc(sizeof(int*)), if (i==NULL) **i=5, free(i)
Here you are allocating memory for an int* pointer. But this int* pointer is uninitialized. You must allocate memory for an int and make this int* pointer point to it. Without doing it, you are accessing memory which you are not supposed to which results in Undefined Behavior.
Dr
I mean in real scenario, this isn't valid... or it may cause errors... but here for his simple task this thing should work just fine right!?
Dr
Ohh...
Dr
I thought that way he's writing the location of another pointer.... Now I got it..... why it's not right
Pavel
Extending std namespace like you have done is Undefined Behavior. There are limited cases where extensions to std namespace is allowed. to_string is not one of those cases. You must do something like this instead. https://ideone.com/FdtzVz It doesn't try to resolve std::to_string call before the concrete type is known btw.
Thanks, do you know why the case without std works differently? I've tried with a custom namespace it also uses only overloads that were declared before the template, but if I put everything in the outer namespace then it start considering later overloads as well.
Anonymous
Thanks, do you know why the case without std works differently? I've tried with a custom namespace it also uses only overloads that were declared before the template, but if I put everything in the outer namespace then it start considering later overloads as well.
It is a combination of ADL and namespace lookup. If your template function and the arguments are defined in specific namespaces, then all overloads in those namespaces will be considered irrespective of where they are defined as long as your template function is accessed through that namespace. If not then only the namespaces of the arguments will be considered. If the arguments are not of a class type then only those overloads which are in scope before the template function will be considered.
Ludovic 'Archivist'
It is a bit weird, but that is why it works
Pavel
It is a bit weird, but that is why it works
I need to save this as a quote :D
Anonymous
The namespace resolution will try to find a function first in current context, then in the namespace where your class is declared
If a matching overload is found in both places and they are both equally viable, then it is ambiguous btw
Pavel
Thank you both
Anonymous
Oh, so it also depends on the namespace from where I call it? Interesting, need to try some of the things, and will read about ADL, I see it's a big topic
It is not dependent on the namespace from which you call it. What I meant is that a qualified name for a template function automatically adds the namespace qualification to the list of namespaces searched. The namespace you are calling it from doesn't matter. If you use an unqualified name, then the compiler uses the namespaces of the arguments alone to determine which namespaces to look up.
鎽 dev
@Lema121 its an spammer, please ban it!
Ludovic 'Archivist'
If a matching overload is found in both places and they are both equally viable, then it is ambiguous btw
I know, i have a running issue with std swap and my own freestanding swap that is extremely annoying
Anonymous
Hii
Peace
How to use codeblocks profiler ?
Anonymous
Hello Everyone .. i have questions that .. #include <iostream> using namespace std; int main() { int digit ,myNum,total; myNum /= 10; digit = myNum % 10; total = digit; cout << total << endl; return 0; } why the output is = 9 and why if i delete -> total = digit;
Anonymous
then i did cout << digit << endl; print 8 instead of 9
Anonymous
Why do you expect 9 ?
that's my questions means i have just tried it and it shows this
Anonymous
anyone with mathematical programmer can explain it ?
stranger
that's my questions means i have just tried it and it shows this
The value of the local variable without initialization is garbage. So you can't say for sure what will the answer be. It will change according to machine and compilers.
stranger
anyone with mathematical programmer can explain it ?
For your answer myNum has any random integer in it within it's range.
Ángel
[C memory leaks] Anybody know how to check for memory leaks without valgrind?
Ammar
Compile with -fsanitize=address and link with -lasan.
Ángel
Thanks!!! Lets me try!
Khaerul
Compile with -fsanitize=address and link with -lasan.
nice info Sir ================================================================= ==7056==ERROR: LeakSanitizer: detected memory leaks Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7f5e68f26279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x55bfff4251a1 in main (/tmp/a.out+0x11a1) #2 0x7f5e68cc9b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24) SUMMARY: AddressSanitizer: 4096 byte(s) leaked in 1 allocation(s).
Ayushi Gupta!!😼
Hey..can anyone suggest me any gud YT channel to learn C language for beginners?? 🥺
Ayushi Gupta!!😼
Use freecodecamp.org
Okayy thanx !!
Ssssss
how to find duplicate in an array?...what is accumulate keyword?
Naina
In c++ how do I search for a particular pair in vector- pairs ?? Is there any function I can use to accept the key value from the user and then search for that pair ?
Naina
how to find duplicate in an array?...what is accumulate keyword?
You can try using a for loop to check for the duplicate element present in the array , u should loop through all the elements in the array and check for each element in the array , if any two elements are equal then that is the duplicate element .
Naina
Is find() not helpful?
I don't think so , it is only helpful in finding if the element is present in the array or not , u can't know how many times the element is repeated
Poornima
how to find duplicate in an array?...what is accumulate keyword?
Array of ? If array of int, then if you can use unordered_set in addition to array , keep inserting into set. If insert fails which means it's duplicate.
Anshul
In c++ how do I search for a particular pair in vector- pairs ?? Is there any function I can use to accept the key value from the user and then search for that pair ?
You can use lower bound(lb) and upper bound function(ub). And then do ub-lb to get how many times that element is present. But for this the array needs to be sorted
Anshul
Otherwise you can use a multiset to store values and then use count() function
Anshul
isn't multiset a bit overkill?
Multiset will take O(nlogn) time. A for loop based approach will take O(n2) time
dearfl
im confused...
Anshul
Nlogn time to insert n elements. And logn time to count for a particular element. So overall complexity will be O(nlogn+logn) i.e. o(nlogn)
Ni
Hey, guys a quick question: auto map = std::unordered_map<std::string, int>("string", 5); why I can't construct a temporary unordered_map with a key of std::string type
dearfl
Nlogn time to insert n elements. And logn time to count for a particular element. So overall complexity will be O(nlogn+logn) i.e. o(nlogn)
nonono, I mean I'm confused what he want...isn't he want to count how many specific pair exist in a vector<pair>
Anshul
I think she/he wants to know how many times a particular pair occur in the vector
Ni
What's the error msg
No matching constructor for initialization of 'std::unordered_map<std::string, int>' (aka 'unordered_map<basic_string<char>, int>') [clang: ovl_no_viable_function_in_init]
dearfl
I think she/he wants to know how many times a particular pair occur in the vector
so count(v.begin(), v.end(), key) * count(v.begin(), v.end(), val) ?
Anshul
so count(v.begin(), v.end(), key) * count(v.begin(), v.end(), val) ?
No map just needs an iterator to that particular element in the vector. Or you can give the pair as an argument
Anshul
so count(v.begin(), v.end(), key) * count(v.begin(), v.end(), val) ?
I think Using count function of algorithm header file is not the efficient way to do it. (Correct me if I'm wrong)
Ni
What are you trying to do? If you want a dynamically created map then it's not the way to do it
inline vector<unordered_map<string, double>> Expreiments::generateStringKeyDoubleValueArray(int arraySize) { vector<unordered_map<string, double>> ret; for (int i = 0; i < arraySize; ++i) { unordered_map<string, double> keyValues; // 1 string randomKey = generate10CharRandomString(); auto randomValue = generateRandomDouble(); keyValues[randomKey] = randomValue; // 2 ret.push_back(keyValues); // 3 ret.push_back(unordered_map<string, double>(randomKey, randomValue)); // 4 } return ret; }; I want just delete 1, 2, and replace 3 with 4, which seems more simple to me, but why I can't do that
Anshul
But whatever.
Ni
oh, well~~~, I may use the original way, and thanks for your help!!!
dearfl
then I dont understand why not use std::count
dearfl
o(n) right?