Shuhash
Is there any inbuilt Library function to Remove space in the string
Anonymous
Is there any inbuilt Library function to Remove space in the string
You have in <cctype> the function std::isspace() Just iterate over the string and copy it, omitting all characters which return a non-zero value
Anonymous
or remove the spaces if it's a std::string, I guess
Anonymous
Thanks for your response is there any other idealogy
Not in the standard library, I'm afraid. If you don't want to implement it, copy one off of Google.
Anonymous
You know what, you can use this:
Anonymous
https://stackoverflow.com/questions/83439/remove-spaces-from-stdstring-in-c
Mystic
Can anyone tell what should I do first
Mystic
dsa or c++
⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠
Is there any inbuilt Library function to Remove space in the string
If it's C++, you can find and erase it. If it's C, I think you can use temp var to put non space char, use isspace() function to check the char
Anonymous
What's happening here? template<typename T, typename U> Is there some way the priority_queue class is implemented that it manages to pass the value type and container type data to comp? Otherwise how? If it's not too much, can you show an example by manually writing a class instead of priority_queue?
No. There is nothing in the priority_queue implementation that allows deducing of template arguments for comp. CTAD doesn't apply here. If you look at my code, I had specified that comp is a template class with the default template parameter being void. Then I specialise this class for void and make operator() inside it a template function instead of a regular function. This method has two template parameters T and U which are inferred by the compiler automatically when this method is called. In instantiating the priority_queue, I specify comp<> as the type which means that it uses comp<void> as the type because void is the default type. So it uses my specialization of comp for void as the concrete instance and uses its operator() for comparisons within the priority queue. The compiler will then infer T and U as int automatically.
Anonymous
This is exactly what happens when you use std::greater<>. It defaults to std::greater<void>
_
can one declare a string data type in c as: typedef char* string; ? Is there another way besides declaring an array of characters?
Anonymous
can one declare a string data type in c as: typedef char* string; ? Is there another way besides declaring an array of characters?
And then what? It would be kind of confusing, because it's just a pointer and not actual data.
Anonymous
char* gives you the right impression that you are using a pointer to an array of chars.
Anonymous
how does one create a custom data type such as a string?
in C, since it's not object oriented, you would need to implement a struct which has a pointer to the char*, size and possibly more. functions to manipulate it like add/remove/modify characters, etc.
Anonymous
Anonymous
i mean in code
Yeah, why? I think it was clear enough.
_
Yeah, why? I think it was clear enough.
i want to use it as a reference when i try to implement the string
Anonymous
Just make something like what I said.
Anonymous
If you really want abstraction, I am not sure why you don't hop over to c++
Anonymous
Because the standard library there abstracts it with std::string
Smita
Can anyone tell me how to develop logic for any program in c language
Anonymous
I tried with only T for both a and b, and it seemed to work, so ig that's fine. But how are T and Q inferred by the compiler? The compiler automatically determines the type of data with which we call comp<>()? Also, why do we default the template parameter to void, as in <typename T=void>? Shouldn't <typename T> be enough, because when we specialize with, say char, we don't need to default T to char.
I specified T and U because that is what std::greater template does. Using two different template types allows more flexibility because that would allow you to compare an int with a float say. We default the template parameter to void because if we don't then the compiler would complain about us not having supplied a template argument when we specify comp<>. That is a non deduucing context and the compiler can't figure out which specific template argument to instantiate comp with. By specifying void as default, the compiler will use comp<void> specialization when we don't specify the template argument The compiler is able to deduce T and U because it is a function call and that is a deducible context. Looking at the priority_queue implementation, the compiler knows that operator() method inside comp will be called with 2 integers in your specific case and hence will be able to deduce T and U as both ints. This deduction can't happen for comp itself (when the default void parameter is not there) because that is what is called a non deducible context in the standard. So in that case we will have to specifically help the compiler and specify comp<int> instead. In the case where void is the default template parameter argument, the compiler always infers comp<> as comp<void>.
Anonymous
Thank you 😊
aishu
#include<stdio.h> void number(int n){ static int num=7; printf("num+n=%d",(num+n)); printf("\n"); num=num+2; } int main(){ number(5); number(5); return 0; } /*o/p: num+n=12 num+n=14*/
Zishan
Help me to solve my problem
klimi
Help me to solve my problem
you haven't posted your problem
Isaac
pls who can give me a guide to c++
Isaac
i am new to the programming language
Isaac
and i just was a detailed guide
Anonymous
suppose you have two sequences for positive integers A[1...n] and B[1...n]. You wish to find the heaviest common subsequence. The heaviest common subsequence between A and B is the subsequence that has the maximum sum of entries. For ex, if A = 2 2 4 8 5 and B = 2 8 4 5 6, then 2 8 5 is the heaviest weight subsequece of A and B. can someone help me solving this problem. I am unable to build the logic...?
aishu
What is the difference between %p and %u control strings for denoting address of a variable?
Anonymous
What is the difference between %p and %u control strings for denoting address of a variable?
%p will print the address in hexadecimal format, and %u will print the address in decimal format...
Kweiwen
hi friends, i would like to design an advanced data structure based on DAG, but seems i've encountered some problem: 1. according to the legacy DAG, the node contains only one input and output, how about a node contains multiple inputs and outputs port? 2. what's the corresponding sorting algorithm? i assume the legacy DAG Sort is not compatible with above requirement. if you know some terms and key words of this kind of design, please kindly share with me! much appreciate.
M. Wahyu
Source for learn embedded system/software ?
Anonymous
#include <iostream> using namespace std; // area = (lngth * width); // peri = 2 * (lngth + width); class perimeter; class Area { int length; public: void setData(void) { cout << " entre the value of Length : "; cin >> length; } friend int area(Area, perimeter); friend void Parameter(Area, perimeter); }; class perimeter { int width; public: void setData(void) { cout << " enter the value of width : "; cin >> width; } friend void Parameter(Area, perimeter); friend int area(Area, perimeter); }; void Parameter(Area A1, perimeter p1) { cout << " the parameter is " << 2 * (A1.length + p1.width); } int area(Area a, perimeter p1) { return (a.length * p1.width); } int main() { Area a; perimeter p; a.setData(); p.setData(); area(a, p); Parameter(a, p); }
Anonymous
problem in area function . the function is not returning the value of length * width , if i do cout« length * width it is working but if im doing return length * width it is not working , why ?? }
Anonymous
It seems area returns an int, but you don't save it anywhere
Anonymous
Hello
Anonymous
I have a question as I do the multiplication table from 1 to 10. I'm very busy.
Anonymous
It seems area returns an int, but you don't save it anywhere
so what should I do next and how to save it , i cannot understood the meaning of save ?
Anonymous
I have this code
Anonymous
and then if u print res
Anonymous
u would get the results
Anonymous
did you mean create a variable and store the area and print the variable
Anonymous
What's the issue right now? you said "area is not returning". But u don't return it to anything.
Anonymous
You gotta assign some lvalue to it
Anonymous
Anonymous
But i need this form
Anonymous
Side by side
Dima
lol
NagaRaju
Here I'm trying to debug the C code using lldb and clang compiler. ~ $ clang -g clang/strCompare.c -o a ~ $ lldb a (lldb) target create "a" Current executable set to '/data/data/com.termux/files/home/a' (arm). (lldb) b 18 Breakpoint 1: where = amain + 20 at strCompare.c:19:11, address = 0x00001528 (lldb) b 25 Breakpoint 2: where = amain + 80 at strCompare.c:26:9, address = 0x00001564 (lldb) run error: failed to launch or debug process (lldb) I don't understand why debugging process is not starting. Can anyone explain me where I was wrong ?
Anonymous
Make chmod of this file 775. anyone explain me about this
Dredd
can someone help me in my code it's not taking my inputs
Dredd
#include <iostream> using namespace std; struct Employee{ string name; struct Employee *next; }; void insert (struct Employee** head, string employee_data){ struct Employee* newEmployee = new Employee; newEmployee-> name = employee_data; newEmployee-> next = (*head); (*head) = newEmployee; } void displaylist(struct Employee *employee){ while(employee != NULL){ cout << employee->name << endl; employee = employee ->next; } } int main() { struct Employee* head = NULL; int x; string name; cout << "How many Employee you want to add to the list: "; cin >> x; for(int i = 0; i<x; i++){ cin >> name; insert(&head,name); } cout << "Name of the Employee: " << endl; displaylist (head); return 0; }
Jagadeesh
anyone know how to choose random elements from array ?
Anonymous
Is there a reason you used constant lvalue reference in the first operator function, but rvalue in the second?
In the first operator function, it is const lvalue for a reason. A struct which compares two values should not have to change it. It being a const reference can accept both lvalues and rvalues. In the 2nd operator, the arguments are not rvalue references. They are universal references which are much more powerful than const lvalue references in that they can be used for perfect forwarding and also be used with both lvalues and rvalues. When you have a template function, making your arguments a universal reference is usually a good idea barring a few cases. The exceptional cases are documented in Scott Meyers' Effective Modern C++.
Anonymous
..Why is the very hard to understand friend function ..🥲🥲
coal
..Why is the very hard to understand friend function ..🥲🥲
its the same as a friend class but within a function