shi
Is there any freelance programmer here?
Rio
How to write a Matrix using codeblocks ?
Rio
??
klimi
Are you writing in c or c++ or codeblocks language?
Ahmed
You mean you want to add all the values in a specific vector?
The vector is dynamic storing allocation so is possible to add as many as new values. So yes
Aron
I have to sleep. had brief look. Just parse/deserialise xml and extract first Previous object from a collection
Medi
Hi, is there any way using kind of regexp format that string str1 str2 str3 1 2 3 4 5 and get only the integers, having in mind can be 5 numbers or more
Edward Wu | Happy Hacking !!
Hello , I'm new at learning C++ I have some questions.
Edward Wu | Happy Hacking !!
Hello , I'm new at learning C++ I have some questions.
mine compile platform can't copy code out , so I can't pasete to anyway. I only can post screenshot to website
Aron
I need som help
Anonymous
How to check whether the input is integer or not ?
Anonymous
Like if I need to add all the digits of an integer 245 output as 11
Anonymous
If input is 2a5 then I need to recognise it as invalid integer
Anonymous
Please help me out
Anonymous
Please help me out
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main() { int sum = 0; char n; /* Input integer from user */ printf("Enter the integer: "); scanf("%c", &n); if (isdigit(n) ==0) { while (n != 0) //this will not work if n is char type { sum = sum + n % 10; n = n / 10; } printf(" %d ", sum); return 0; } else { printf("Input entered is invalid"); } }
Anonymous
ctype.h
I had put already in code
⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠
Anonymous
No
Anonymous
Input : 256 Output : 13
Anonymous
Input : 4a1 Output : Invalid
Anonymous
That's what I needed
⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠
You're make a flood on the stream. Use array of char, do some check, then convert to int
Well we don't need to convert it to int. Just do check first, then go for the algorithm
Hsn
Float × int = (float or int) ? Float / int = (float or int)?
914
Both should be float
VladV1V
is there any way to use , in float numbers instead of .
Igor🇺🇦
is there any way to use , in float numbers instead of .
It's called floating point number, not floating comma number 😉
VladV1V
It's called floating point number, not floating comma number 😉
oh ... Well i made calculator and my teacher tells that for numbers i need to use 1,2 for example instead of 1.2 googled and didnt find what to do...
VladV1V
What does it mean "use"? You mean like parse use input or use in code?
i mean in input for example: input 1,2+1,3 instead of 1.2+1.3
Igor🇺🇦
Ah, that's different. Just parse them character by character till you reach comma. N = N *10 + current_char
Igor🇺🇦
After comma do the same for numbers after comma. After you finish divide it be 10^(size of string after comma). Your number is a sum of both numbers.
Peace
This program is showing error : binding reference of type 'int&' to 'const int' discards qualifiers It is working fine when I do not use const. Why ? int &print(const int a){ return a; } int main(){ int a=1; cout << print(a); return 0; }
Pavel
This program is showing error : binding reference of type 'int&' to 'const int' discards qualifiers It is working fine when I do not use const. Why ? int &print(const int a){ return a; } int main(){ int a=1; cout << print(a); return 0; }
You basically trying to return a non-const reference to a local const variable. This is not allowed (because it's breaking the const-correctness of the code). This is not correct by one more unrelated reason, returning reference (any const or non-const) to a local variable can result in undefined behavior.
Peace
when returning by reference is useful ?
Pavel
when returning by reference is useful ?
I don't get the question
Peace
when does returning value by reference is useful ? which situations ?
Peace
we can return value by value , address . then why do we return by reference ?
Peace
a basic question :use of returning value by reference
Pavel
when does returning value by reference is useful ? which situations ?
One example can be returning a reference to a member variable of a class. Imagine you have some class that stores heavy data as a private member variable, you want the users of this class to read this data without copying it, you can make a getter function that returns a const reference to that data.
Igor🇺🇦
we can return value by value , address . then why do we return by reference ?
Returning by value means we create a copy of the object with the same value and return it. Refence means we return the same object.
Pavel
it means without copying data we can read it , edit it.
If it const, then only read it but not edit, if it non-const, then edit too.
Pavel
what is RVO or NRVO ?
You can Google it
Pavel
what is RVO or NRVO ?
https://shaharmike.com/cpp/rvo/
Igor🇺🇦
Not necessarily, if there's RVO or NRVO happening it can be the same object.
With these optimizations we don't return any object at all ,so it's not returning by value If you want to be that pedantic
Buki
Any C++ graphics designerr inbox
klimi
Any C++ graphics designerr inbox
don't just spam...
Peace
https://shaharmike.com/cpp/rvo/
it's high level for me 😁
Pavel
it's high level for me 😁
Then just the simple rule - don't return references to local variables. Unfortunately compiler won't stop you from doing that.
Kaashᅠ
how can we parse cout data into a variable? Can it happen? in C++
Бүләт
Hi! How can I read one line until '\n' from text file, using only open, read, malloc and free functions? BUFFER_SIZE in read(fd, buf, BUFFER_SIZE) everytime different and sets by user. Function must be written on C
Бүләт
Using Linux syscall ?
I cant use it) Only: open, read, malloc, free. And ok, I can write my own strlen and other functions, that use this four functions
✨Justina
#include <iostream> using namespace std; int findLargest(vector<int>&); int main() { vector<int>hebat; int Size; int Value; int Largest; cout<<"How many integers would you like to enter?"; cin>>Size; for (int i=0; i<size; i++) { cout<<"Enter your Number "<<i+1<<":"; cin>>Value; hebat.push_back(value); } Largest = findLargest(hebat); cout<<"The Largest Value is :"<<Largest; return 0; } int findLargest(vector<int>& temp) { int max=temp[0]; for(int j=i; j<temp.Size();j++) { if(temp[j]>max) max=temp[j]; } return max; }
✨Justina
plz help to solve this problem
artemetra 🇺🇦
plz help to solve this problem
what's the problem? what part of code do you have problems with?
artemetra 🇺🇦
what's the error, then?
✨Justina
#include <iostream> using namespace std; int findLargest(vector<int>&);
✨Justina
At this part
artemetra 🇺🇦
you haven't specified the parameter name
✨Justina
Bcoz 1st time I'm doing vector question
artemetra 🇺🇦
olli
#include <iostream> using namespace std; int findLargest(vector<int>&);
A decent compiler will tell you what's wrong there (however there are more compiler errors) <source>:3:17: error: 'vector' was not declared in this scope 3 | int findLargest(vector<int>&); | ^~~~~~ <source>:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'? 1 | #include <iostream> +++ |+#include <vector> 2 | using namespace std; <source>:3:24: error: expected primary-expression before 'int'
artemetra 🇺🇦
your function declaration (findLargest with the ;) signature must match the function definition signature (findLargest in the bottom with {}) otherwise, the compiler will see those functions as different
artemetra 🇺🇦
but yeah, you have a syntax error there https://t.me/programminginc/428149
✨Justina
#include <iostream> #include <vector> using namespace std; int findLargest(vector<int>&temp); int main() { vector<int>hebat; int Size; int Value; int Largest; cout<<"How many integers would you like to enter?"; cin>>Size;
✨Justina
Nw this part correct rdy