Shao
who it's so good
Shao
Huh? I found out the wrong number
Vidya
Anyone has error or doubt in c++ program can tag me to get answers.
Anonymous
SR27
Anonymous
I want simple c++ game
To learn how to programming
Anonymous
With source code
Sketchyyy
Anyone has error or doubt in c++ program can tag me to get answers.
I have wrote a program (in C++) which takes a number as input and tells whether the provided number is prime or not (not directly related to my problem).
I am taking input via std::cin etc.
Instead I want to take input as command line arguments. Eg. : ./program_name <number_here>
so... how can i change this <number_here> to an 'int'?
I am using following script to take input, but I am unable to figure out how to convert it to an 'int'. :
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
// code to convert argv[1] to an int?
return 0;
}
Sketchyyy
Thanks.
Unknown
Sketchyyy
;-; it was an internal ink...
Sketchyyy
\Device\NUL
\Device\NUL
It just convert string into integer
Sketchyyy
strtod ?
Shows some error... Lemme replicate
Sketchyyy
It just convert string into integer
It's not a string it's a char...
Error :
a value of type "char *" cannot be assigned to an entity of type "int"
klimi
@K11M1
https://stackoverflow.com/questions/7663709/how-can-i-convert-a-stdstring-to-int
\Device\NUL
klimi
\Device\NUL
klimi
https://stackoverflow.com/questions/2797813/how-to-convert-a-command-line-argument-to-int
klimi
this might be more accurate then
Sketchyyy
Nomid Íkorni-Sciurus
Guys do you know an open alternative to VSTs ?
Nomid Íkorni-Sciurus
I know of LADSPA but I'm not sure it will work under Windows.
Hanza
Which is the best compiler for c++?
\Device\NUL
I will recommend clang/gcc
Hanza
Thank you ❤️
Armin
Hi I have this bucket sort template function that works fine. The only problem is it has a code duplication.
template<class ForwardIterator,
class = typename std::enable_if<std::is_floating_point<typename ForwardIterator::value_type>::value>::type>
inline void bucket_sort(ForwardIterator first, ForwardIterator last, std::size_t n) {
using Float = typename ForwardIterator::value_type;
// ...
}
Can I somehow use that Float alias inside the template parameter?
Armin
Ludovic 'Archivist'
Armin
hamza
𝖏𝖔𝖘𝖊𝖕𝖍𝖎𝖈̧
Hello everyone.....I was just asking if you could help me code a program that can read 100 integral values,arrange in ascending and descending order and also output the largest and the smallest number....kindly
Tushar
Unknown
Recommend something
Book references
C How to program (paul deitel harvey deitel) 6th
C++ How to program (paul deitel harvey deitel) 8th
Programiz as online reference
Also another thing if you start with C, C++ will be easier to learn, and then move to C#
λalo.alo
Muskan
#include<iostream>
#include<conio.h>
using namespace std;
class distance
{
private:
int feet ;
double inches;
public:
void setdata();
void showdata();
distance add_dis(distance);
};
void distance::setdata()
{
cout<<"enter distance in feets and inches";
cin>>feet>>inches;
cout<<endl;
}
void distance::showdata()
{
cout<<"distance is"<<feet<<":"<<inches<<endl;
}
distance distance::add_dis(distance dis2)
{
distance temp;
temp.feet=feet+dis2.feet;
temp.inches=inches+dis2.inches;
if(temp.inches>12) //1 feet=12 inches
{
temp.feet++;
temp.inches=temp.inches-12;
}
return (temp);
}
main()
{
distance d1,d2,d3;
d1.setdata();
d1.showdata();
d2.setdata();
d2.showdata();
d3=d1.add_dis(d2);
d3.showdata();
return 0;
}
Muskan
Error- reference to 'distance' is ambigious
Pls help
Muskan
Same error
Muskan
Same error
Armin
Hi I have two iterators, first and last which are representing [first, last).
I want to iterate elements between these two in reverse order. Does below code work?
--last;
--first;
for (auto it = last; it != first; --it) {
// ...
}
Does comparing with first - 1 produce any UB?
Anonymous
hamza
Armin
Alviro Iskandar
S__R
Armin
Alviro Iskandar
explain why
the iterator is dereference-able, that means you can read/write the element through it via dereference.
note that out of bound read/write is UB, but having the value of first - 1 does not do any OOB r/w, but dereferencing the value of first - 1 does
Muskan
100$ website
title= atitle;
atitle=title;
whats the difference?
arent both same?
John
smene
Hi everyone :)
smene
I would like to include libcurl into CMake, I am currently using Clion on Windows.. can anyone help me please?
Joo
I want to copy the elements at the last index to the midpoint of char a[ ] into char f[ ] but it doesnt seem to work
Joo
The result at f[ ] isnt consistent with the result at either p or a[ ]
Joo
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a [10];
cout<<Input your number \n";
cin>>a;
char p:
int n=strlen(a);
char
b=0;
int d=n*0.5;
char c[d], f[d];
for(int i=0; i<d; i++){
c[i]=a[i];
}
for(int i= n-1; i>=d; i--){
p=a[i]:
cout<< "Number at "<< i << " is "<<p<<" ";
for(int j = 0; j<=d; j++){
f[j]=p;
}
cout<<endl;
for(int i=0; i<=d; i++){
cout<< "The number at index "<< i <<"is "<<f[i]<< \n";
for(int j-n-1; j>=d; j--){
cout<< "The number at index " <<j<<"is " <<a[j]<<endl;
}
return 0;
}
Anonymous
explain why
It is Undefined Behavior because decrementing an iterator past the first element in a container is Undefined Behavior according to the standard.
smene
I would like to include libcurl into CMake, I am currently using Clion on Windows.. can anyone help me please?
David
1 int main(){
2     //initializing count
3     int count = 0;
4  
5     // individual varuiable for the x and y resultant component
6     double resultantX = 0;
7     double resultantY = 0;
8  
9     // declaring number of vector, angle, magnitude, x any y values
10     double mag, angle, xValue, yValue;
11     int noOfVecetor;
12  
13     // prompt user, asking number of vector
14     printf("How many vectors? ");
15     scanf("%d", &noOfVecetor);
16  
17     while (count < noOfVecetor){
18             // prompt user, asking for the magnitude and
19             printf("Enter vector %d (mag, angle):", count+1);
20             scanf("%lf %lf", &mag, &angle);
21  
22             //resultant x component
23             xValue = x_Component(mag, angle);
24             resultantX = resultantX + xValue;
25  
26  
27             //resultant y component
28             yValue = y_Component(mag, angle);
29             resultantY = resultantY + yValue;
30             count++;
31         }
32         // compute the polar magnitude using the return function
33         double PolarFormMagnitude = magnitude(resultantX, resultantY);
34        
35         // comoute the polar angle with positive x axis using its return function
36         double Angle = angleXaxis(resultantX, resultantY);
37         if (Angle == 0){
38             printf("A 0 vector has no direction nor magnitude!");
39         }
40        
41        
42             printf("\nThe resultant in rectangular form is:");
43             printf("\nx-component = %lf", resultantX);
44             printf("\ny-component = %lf", resultantY);
45             printf("\nThe polar form of the resultant is:");
46             printf("\nMagnitude = %lf", PolarFormMagnitude);            
47             printf("\nAngle with positive x-axis = %lf degrees\n", Angle * (180 / M_PI));
48         return 0;
49     }
David
37, 38 the conditional statement isnt printing
smene
David
David
It’s just cuz if indentation
Armin
Sergio
Why binary search tree not it’s include in STL?
Tushar
were the conversation that we had here just deleted? If so, may I ask why?
Tushar
Anonymous
Struggling with Linked list..
Anonymous
include <bits/stdc++.h>
using namespace std;
// A linked list node
class Node
{
public:
int data;
Node *next;
};
/* Given a reference (pointer to pointer)
to the head of a list and an int, inserts
a new node on the front of the list. */
void push(Node** head_ref, int new_data)
{
/* 1. allocate node */
Node* new_node = new Node();
/* 2. put in the data */
new_node->data = new_data;
/* 3. Make next of new node as head */
new_node->next = (*head_ref);
/* 4. move the head to point to the new node */
(*head_ref) = new_node;
}
/* Given a reference (pointer to pointer) to the head
of a list and an int, appends a new node at the end */
void append(Node** head_ref, int new_data)
{
/* 1. allocate node */
Node* new_node = new Node();
Node *temp = *head_ref; /* used in step 4*/
/* 2. put in the data */
new_node->data = new_data;
/* 3. This new node is going to be
the last node, so make next of
it as NULL*/
new_node->next = NULL;
/* 4. Else traverse till the last node */
while (temp->next != NULL)
{
temp = temp->next;
}
/* 5. Change the next of last node */
temp->next = new_node;
return;
}
// This function prints contents of
// linked list starting from head
void printList(Node *node)
{
while (node != NULL)
{
cout<<" "<<node->data;
node = node->next;
}
}
void createhead(Node** head_ref, int new_data)
{
/* 1. allocate node */
Node* new_node = new Node();
/* 2. put in the data */
new_node->data = new_data;
*head_ref = new_node;
return;
}
void printxyz(Node**head_ref){
Node*sptr=*head_ref;
Node*fptr=*head_ref;
while(fptr->next!=NULL)
{
fptr=fptr->next->next;
sptr=sptr->next;
}
cout<<"\n The xyz element="<<sptr->data<<endl;
}
int main()
{
Node*head_firstLinkedList=NULL;
createhead(&head_firstLinkedList,11);
append(&head_firstLinkedList,6);
push(&head_firstLinkedList,7);
push(&head_firstLinkedList,1);
append(&head_firstLinkedList,4);
/* Start with the empty list */
// Node* head = NULL;
// Insert 11. The linked list becomes 11->NULL
// createhead(&head, 11);
// Insert 6. So linked list becomes 11->6->NULL
//append(&head, 6);
// Insert 7 at the beginning.
// So linked list becomes 7->11->6NULL
//push(&head, 7);
// Insert 1 at the beginning.
// So linked list becomes 1->7->11->6->NULL
//push(&head, 1);
// Insert 4 at the end. So
// linked list becomes 1->7->11->6->4->NULL
//append(&head, 4);
cout<<"Created Linked list is: ";
printList(head_firstLinkedList);
printxyz(&head_firstLinkedList);
return 0;
}
Task 1: Put the elements of the first linkedlist in the reverse order in a second
Step 1: Create a new linkedlist
Step 2: Traverse the first linkedlist and read the data of each node.
Step 3: As you read the data of each node, insert a new element to the second linkedlist
Step 4: Print the new linkedlist
Anonymous
Thanks
Amrith
What is the actual purpose of linked lists? Where is it used in real life programming?