|
I'm tooling around with C++, mostly trying to learn stuff. Suppose I would want to test if I'm out of bounds of my allocated array, is this ok? code:
code:
edit: I could of course check for the last position in the allocated array instead but I'm curious.
|
# ¿ Nov 22, 2011 12:41 |
|
|
# ¿ May 17, 2024 01:27 |
|
Allright, thanks!
|
# ¿ Nov 22, 2011 14:09 |
|
Can anyone recommend a CSV-parser function/library that has no problem chewing through gigabyte size files without loading the whole thing into memory? I'm tinkering around with my own but it seems to me that this problem should be solved by now. Thanks.
|
# ¿ Nov 28, 2011 14:48 |
|
I'm probably missing something. Say I have a class with a method. When I set up the class, at runtime I want the method to do either something A or something B. But I want it to do the same thing every time. Pseudocode: code:
I can solve it by making two different classes inherit from a base class but I'm curious as to if it's possible some other way?
|
# ¿ Jan 14, 2012 11:36 |
|
brosmike and Dicky B posted:... Thanks! I'm mostly using this as a learning/experimenting thing and CSV-files is something I'm familiar with and do a lot of work with so that's why I'm using them as subject matter. Regarding the other things (separator, column names etc), those are common to both cases so I have to take care of them regardless. I'll poke around the stuff you mentioned and see what I can pick up.
|
# ¿ Jan 14, 2012 13:10 |
|
If I have a vector<vector<char> > and do a push_back with a new vector<char>. Will that invalidate any vector<char>::iterators to previously stored content?
|
# ¿ Jan 26, 2012 13:19 |
|
It compiles fine here but it segfaults when run so it seems the iterators are invalidated. I suspected as much, thanks for the help. Bugger. (was at work when posting the question, with no compiler in sight)
|
# ¿ Jan 26, 2012 17:38 |
|
Gerblyn posted:You could just use vector<vector<char>*> (or smart pointers) with dynamically allocated vector<char>s instead, your iterators would be fine then. prolecat posted:If instead you stored pointers to the nested vectors, their iterators would be safe since their contents wouldn't be moved around when the containing vector was reallocated. Yeah this is probably the way I'm heading. Thanks again.
|
# ¿ Jan 26, 2012 17:51 |
|
The below works fine as long as I keep it in my main but as soon as I try to move it to a function it leads to not being able to bind to the statement further down. The work I try to do: code:
code:
code:
1. I'm not preparing the statement I think I'm preparing when I pass the pointer to the sqllite3_stmt? SQLite is not complaining so far though. 2. If not the above then it's something to do with the statement needing to remember the query text and that goes out of scope when the function exits. This would mean that it working for me is purely coincidental since I'm reusing the same std::string multiple times. InAndOutBrennan fucked around with this message at 12:50 on Dec 30, 2012 |
# ¿ Dec 30, 2012 12:45 |
|
nielsm posted:...awesome... Well, that did the trick! Thanks! Sorry for not posting all of it but I figured I got the important bits in there. As soon as I think I get those loving pointers down...
|
# ¿ Dec 30, 2012 13:48 |
|
In an effort to put together a simple hobby project with "proper" composition for once I'm passing structs around a lot more than I have before (granted I'm a lovely C-programmer but we're here to learn right?). I'm a bit confused as to why this works. I would assume that I'd need to malloc the struct somewhere? Should I? What happens if I do, what happens if I don't? Thanks. code:
|
# ¿ Sep 18, 2014 09:05 |
|
"Proper composition" just means that I try to put together stuff in a nicer way instead of just writing hugeass functions that do 100 things at once. Thus passing around data a lot more than I'm used to. Problem is that it compiles, runs and produces the "desired" result. But in this case this is just luck? As I said I expected to have to do it and was surprised when everything "worked" without it. Running with valgrind does indeed generate a warning about uninitialized pointers. Thanks. sarehu posted:...good stuff..
|
# ¿ Sep 18, 2014 11:48 |
|
|
# ¿ May 17, 2024 01:27 |
|
Just random thoughts from a hobby c++ writer here. My production code tends to be written in stuff you would expect in the data place. But poo poo is it interesting to dip in and out every 6 months to learn something new. Looking at some code I have in both python and C++ the difference is really minimal in structure these days. 15 years ago it would have needed so many "helper" functions and classes that now are part of the std. Yes you can dip down and roll your own poo poo when needed but from someone where every project is greenfield it's just so nice these days. TLDR: Haven't used new or malloc in ages. And yes I understand, different strokes.
|
# ¿ Feb 18, 2024 13:27 |