Anonymous
What do you mean ؟ 🤣
Persian or English
س💕 ⚖️
English
Anonymous
Wat
The header file Now you know about it Try it and see
Anonymous
English
Then you would have understood me
Anonymous
It's not standard C++
Why Is it because it's old😢
Anonymous
Why Is it because it's old😢
Because it's not in the standard
Anonymous
😂😂
Anonymous
I will forget about iostream.h
Shubh
Coffee key, [16/02/2021, 20:08] #include <stdio.h> int main() { int y; printf("Enter your year"); scanf ("%d",&y); if(y%4==0) printf ("your year is leap"); else printf ("your year is not leap"); return 0; } Is program me if me jo condition likhi he usme samaj nahi aa raha
S__R
i don't understand your question dude :(
he saying if condition he can't undersatand
Jas
he saying if condition he can't undersatand
It’s just using mod4 to see whether or not it’s a leap year. You sure that’s his question?
Mahdi
Hi
Anonymous
Anybody know how to read input of csv file in c program
Anonymous
Anybody know how to read input of csv file in c program
did you search in google before asking here?
Anonymous
Yes
Anonymous
But i tried..not getting output
Anonymous
Cracker plz dont PM me
Anonymous
Okqy
Anonymous
Can u tell me to get output
Anonymous
What
Nish
new to C++, why wouldn't this range based for loop work within a function? int sumArray(int arr[]) { int sum = 0; for(int i:arr) { sum += i; } return sum; }
Asad
Range based loop does not work with built-in arrays. You can only use it with STL collections.
Asad
No?
Nish
you mean vector? but in general, i was just trying to understand if there's anyway to make the range based loop work in this case? @khasanovasad . As I mentioned I am new to c++, so this is more for learning than anything else
Asad
Range based loop does not work with built-in arrays. You can only use it with STL collections.
I thought it only works with collections that has begin() & end()
Nish
aah, so it does need those iterators and built in array doesn't have them. Would that be a correct statement?
Asad
No, I just found out that it also works with built in arrays in the same scope you declared them. When you pass an array to a function, you are not actually passing an array. You are passing a pointer that acts like an array. That's why your code does not work.
Nish
so how would i pass that by reference in that example?
Nish
i mean i understand that <array> library fixes this as it comes with begin() and end()... i am just curious is all
Asad
so how would i pass that by reference in that example?
I don't think you can do that. The reason is range based loop iterates from 0th index till (size - 1) where size can be found using sizeof(array) / sizeof(array[0]). This expression does not work when array is passed to a function.
Nish
interesting
Nish
so in practice (real world).. would it be safe to assume that people just end up using vectors. If you really need fixed array then the <array> lib instead of built-in ones?
Asad
You should definitely prefer std::vector and std::array over plain arrays
Asad
Yessir
Anonymous
Can anyone help for my test
Henry
/get cbook
Rahul
I am so weak in programming.. Can u guys suggest me where to begin with!?
Rahul
I work on the networking side.. But i wish to pursue basic knowledge in programming too..
Anonymous
/warn promo link without approval
Pavel
new to C++, why wouldn't this range based for loop work within a function? int sumArray(int arr[]) { int sum = 0; for(int i:arr) { sum += i; } return sum; }
Technically it doesn't work because you can't apply std::begin() and srd::end() to pointers. You function parameter is not an array reference (it's a a pointer to the first element of the array). To pass a reference to built-in array you would need to do smth like template<size_t Length> int sumArray(int(&arr)[Length]) {// Your code}
Vlad
new to C++, why wouldn't this range based for loop work within a function? int sumArray(int arr[]) { int sum = 0; for(int i:arr) { sum += i; } return sum; }
template <typename Container> int sumOfInts(Container&& c) { static_assert(std::is_same_v<decltype(*std::begin(c)), int>); // your code below }
Anonymous
## Rules #pinned * You are not entitled to an answer, getting angry about not answered questions will get you warned. * Not checking your problem in google (or any other search engine) first will get you a warn. * Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something. * Before posting a long code snippet think twice and read the Resources section below. * No “best book” or “best youtube channel” requests, use /get cbook and /get cppbookguide chat commands. * No “best ide” requests, use /get ide chat command to see the suggestions. * Asking for something that is in the pinned message right after joining WILL GET YOU BANNED. * C/C++ discussion preffered (assembly also allowed), asking about other languages (or groups for other languages) right after joining will get you BANNED. * Reverse enginnering, hacking and related topics are allowed, but asking to hack facebook, instagram, etc. is NOT allowed. Also if you ask "how to become a hacker" and obviously have zero knowledge on anything related to that you may get warned or banned. * Legitimate requests for help on code and programming questions are welcome. A request is considered legitimate if it describes your problem, what you've done so far and what went wrong. Requests such as "write my program" or "do my homework" are never considered legitimate. Asking not legitimate questions will result in a warn or ban. See https://stackoverflow.com/help/mcve on how to write good questions. * Asking for book recommendations is ok, but "pls give pdf book" is not allowed, find books by yourself. Posting illegally copied books (or links to those books) is also not allowed and will get you BANNED. * Only English language is allowed, if you speak shitty English or don't understand anything in English YOU WILL BE BANNED. * A little bit of programming related memes, jokes, shitposting are allowed. * NSFW content (porn, nudity, etc.) is not allowed. * Spamming/advertising (job posts are also ads, so ask an admin before posting) will grant you a warning or an immediate ban if you do it right after joining. * Religion, politics and ideological topics are forbidden. * Long code snippets must be posted via a snippet website(links below), posting pictures of code and posting long snippets in the group is not allowed. * If you encounter a problem, while using dev C++ or turbo C/C++, you will not be helped, use another more modern IDE. * Don't post compiled executables, that is obviously a security risk. * Personal messages without asking beforehand are not allowed. * If you want to post a link or some article in this chat you will need an admin approval first ## Resources C/C++ group India: http://t.me/c_cpp_india About asking good questions: * [English](http://www.catb.org/esr/faqs/smart-questions.html) * [Translations](http://www.catb.org/esr/faqs/smart-questions.html#translations) For posting long code snippets: * [GitHub Gist](https://gist.github.com) * [Ubuntu Paste](https://paste.ubuntu.com/) * [Pastebin](https://pastebin.com) ## Reports If you notice any forbidden content, please use the /report command while responding to the offending post to report it to the admins.
Understood
Anonymous
hola. gimme a hint on how to dive in cpp enough fast. my aim is to learn oop and patterns to switch after that back to dynamically typed python.
Vlad
But I don't know what is your "fast"
Vlad
C++ is a journey not destination
Anonymous
>C++ >Learn fast I'd suggest you to reconsider
Ty. let me take time out to think about your advice.
Mar!o
new to C++, why wouldn't this range based for loop work within a function? int sumArray(int arr[]) { int sum = 0; for(int i:arr) { sum += i; } return sum; }
#include <span> int sumArray(std::span<int> arr) { int sum = 0; for(int i : arr) { sum += i; } return sum; }
Vlad
I'll learn what that code does
Mine is c++17 way of doing that. Whilst his is c++20
Nish
Mine is c++17 way of doing that. Whilst his is c++20
I understand that you believe it is straight forward. But I am still learning, I don't even understand stl completely yet
Nish
😂😂
Pavel
I understand that you believe it is straight forward. But I am still learning, I don't even understand stl completely yet
What that code does is accept "forwarding reference". Compiler knows whether you passed r or lvalue and accepts it I would not say it's actually a right way to implement your function. It does not make any sense to modify your object inside
Pavel
Hmm
You should not really think about it at the begining. That stuff mostly only required for 3rd party libs or some specific cases. In your case just use std::array which is wraper over built-in arrays
Nish
You should not really think about it at the begining. That stuff mostly only required for 3rd party libs or some specific cases. In your case just use std::array which is wraper over built-in arrays
That makes sense and that's what I did. Since I've got you, here's a question. I am learning c++ (almost done with basics including oop). Gradually the plan is to move to learning data structutes and algorithms. Happen to know any good books that actually explains "WHY"? For example, I know what a linked list is now, but it would have been way easier to understand if somebody had explained why you even need that to begin with instead of concentrating on how to use it.
Adams Scott
yo
Pavel
That makes sense and that's what I did. Since I've got you, here's a question. I am learning c++ (almost done with basics including oop). Gradually the plan is to move to learning data structutes and algorithms. Happen to know any good books that actually explains "WHY"? For example, I know what a linked list is now, but it would have been way easier to understand if somebody had explained why you even need that to begin with instead of concentrating on how to use it.
Data structures have basically nothing with C++ in particular. It's a mathematical abstract subject. The fact you can "implement" them with programming language is just sort of luck. If you think about a dictionary (I mean a book) it is in fact a data structure (ordered vector) and you can use algorithm(binary search) by turning pages to find something really quickly. When you learn data structures you're not really learn language, rather you're understanding programming itself. If you have no experience in programming it's PROBABLY not the bad way to start. If you want to understand WHY you have to learn data structures then think for a second of a map(like Google map) - it does have a lot of objects binded to its coordinates (pair(x, y)), now you should have an ability to print all the objects within a given rectangle. How would you do that really practical task? Assuming you have millions of requests per second? Have you any ideas? Can you come up with any on your own? If you never heard about K-d trees I bet you'll never be able to solve it. You must at least know what data structures can and can't do and how fast they can solve you tasks.
Anonymous
Hey I'm a beginner in C++
Anonymous
I know a bit of Java but that's it
Anonymous
Can you help me?
Pavel
Can you help me?
Hi. You can ask your questions here. Note that a good question contains half of the answer, you can find a link in the rules about how to ask good questions :)
Anonymous
Don't worry. I won't ask questions for tests and the like because I'm trying to teach myself