|
If you mean http://cimg.sourceforge.net/, then you can use GetObject to get the bitmap data and then pass it to the CImg constructor.
|
# ? Feb 20, 2009 03:13 |
|
|
# ? Jun 7, 2024 04:09 |
Randall posted:I just bought Accelerated C++ by Koenig/Moo today. I'm not even on chapter 2 and am already lost. It's been a long while since I started programming, so take this with a giant spoon of salt. The best way to become proficient in a programming language is to use it. Build tiny applications -- simple things like Hello World. Hello (name). A program that takes a text file and adds line numbers. A simple calculator. etc This will teach you something beyond, "Okay public static void main here," and into the realm of understanding WHY things are being done the way they are.
|
|
# ? Feb 20, 2009 03:54 |
|
Jo posted:This will teach you something beyond, "Okay public static void main here," and into the realm of understanding WHY things are being done the way they are. Been hitting the Java a little too hard have we?
|
# ? Feb 20, 2009 06:05 |
|
Looking for a little basic c++ help here, google was insufficient. Is there some standard way of handling template functions properly? The only way I've found to properly implement code:
|
# ? Feb 20, 2009 09:44 |
|
Rahu posted:should I abandon all hope of leaving real code out of headers? This, I am afraid.
|
# ? Feb 20, 2009 10:23 |
|
Templates always go in headers unless you have a compiler that supports export (I can just about guarantee you don't). For further reading, see N1426. (tl;dr: even the people who managed to implement export - it wasn't easy - said it's not worth it)
|
# ? Feb 20, 2009 10:24 |
|
Rahu posted:Is there some more proper way to do this or should I abandon all hope of leaving real code out of headers? code:
code:
Doesn't seem to have caught on so far, but I like it.
|
# ? Feb 20, 2009 11:02 |
|
Parsing in C I've been programming for a long time, and I know C, but I am not a C master. Most of my knowledge on how to manipulate strings is from higher-level languages, and there I'm pretty good at it. In C I'm a bit clunkier, which is bad, because I'm about to write a heavy-duty parser. It would help me to look at some code that shows how a pro would do things. Should I be using free() and strndup() a lot to extract tokens? How should I go about classifying different types of tokens? What's the best way to read essentially the same way from a file or from stdin?
|
# ? Feb 20, 2009 18:34 |
|
functional posted:What's the best way to read essentially the same way from a file or from stdin? Is IO redirection an option? I like it.
|
# ? Feb 20, 2009 18:37 |
|
If you're doing parsing in C, you should first be able to justify why lexx+yacc or a derivative won't work for your situation; they are a lot more robust than building a parser yourself.
|
# ? Feb 20, 2009 18:39 |
|
ShoulderDaemon posted:If you're doing parsing in C, you should first be able to justify why lexx+yacc or a derivative won't work for your situation; they are a lot more robust than building a parser yourself. OK, I will look into that. In the meantime I'm still going to need to know how to do these things myself, since I won't be able to rely on lex/yacc for everything.
|
# ? Feb 20, 2009 19:46 |
|
functional posted:OK, I will look into that. In the meantime I'm still going to need to know how to do these things myself, since I won't be able to rely on lex/yacc for everything. Well, the acts of tokenizing input, creating a state table, and managing all of the minutiae of parsing input are really irritating and difficult to implement well in C. It's a terrible language for it. Lex and yacc can pretty much always do the hardest parts for you, and there are very few good reasons to not be using them; in cases where they won't work for you, knowing how to build regex tokenizers and LALR parsers in C won't help you, because what you want is something else at that point.
|
# ? Feb 20, 2009 20:07 |
|
ShoulderDaemon posted:Well, the acts of tokenizing input, creating a state table, and managing all of the minutiae of parsing input are really irritating and difficult to implement well in C. It's a terrible language for it. Lex and yacc can pretty much always do the hardest parts for you, and there are very few good reasons to not be using them; in cases where they won't work for you, knowing how to build regex tokenizers and LALR parsers in C won't help you, because what you want is something else at that point. Well, if you're going to be implementing a parser in C the only practical option is a recursive-descent parser.
|
# ? Feb 20, 2009 21:25 |
|
What happens if a function that's supposed to return something fails to return?code:
Brief googling says C, and that's what I suspect as well, but I just want to confirm. And holy gently caress Sun CC can lick my balls, this is an important thing to warn about at maximum warning level you loving prick!
|
# ? Feb 20, 2009 23:26 |
|
Ledneh posted:Brief googling says C, and that's what I suspect as well, but I just want to confirm. Wow, that's certainly an overlooked compiler warning.
|
# ? Feb 20, 2009 23:40 |
|
Dijkstracula posted:Wow, that's certainly an overlooked compiler warning. Warnings for something like that can only be emitted properly if the compiler supports something like the noreturn function attribute. Otherwise, this would generate a warning: code:
Avenging Dentist fucked around with this message at 00:01 on Feb 21, 2009 |
# ? Feb 20, 2009 23:58 |
|
On the one hand, I'm HUGELY relieved that I found this because it's going to fix a lot of problems down the road (beyond the one I just solved). On the other, holy gently caress I am STUNNED that Sun CC doesn't emit a warning at any level when not all control paths return. I thought that was kind of a fundamental thing to watch out for. (edit) On the THIRD hand, I could just find the guy who wrote that piece and throttle him. I bet I know who it is too. Argh.
|
# ? Feb 20, 2009 23:59 |
|
ISO C++ Standard posted:Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function. So that's (C). With POD types, you'll usually just get an undefined value of some sort, which of course will generally lead to undefined behavior if used. Pedantic comment: returning values via the stack is the exceptional case on most platforms, not the norm.
|
# ? Feb 21, 2009 00:05 |
|
functional posted:OK, I will look into that. In the meantime I'm still going to need to know how to do these things myself, since I won't be able to rely on lex/yacc for everything. You might start with strtok() ("string tokenizer".) You'll probably find other helpful stuff in "string.h" too.
|
# ? Feb 21, 2009 05:56 |
|
Note that strtok is generally not thread-safe.
|
# ? Feb 21, 2009 05:57 |
|
Speaking of string functions, I'm porting a side project that I started working on in OSX to Linux and I see that the strlcpy/strlcat functions don't appear to be in Interpid's glibc...any idea why this might be the case? Is this just an Ubuntu thing, or is it not to be found anywhere in Linuxdom? At school we had "STRLFOO(), NOT STRNFOO(), AND CERTAINLY NOT PLAIN OLD STRFOO(), YOU IDIOTS" beaten into us, and those machines were all running Linux, so maybe the functions were added in after the fact...? I'd make a disparaging comment about Linux, but I think I'll save that for YOSPOS.
|
# ? Feb 21, 2009 06:36 |
|
Dijkstracula posted:Speaking of string functions, I'm porting a side project that I started working on in OSX to Linux and I see that the strlcpy/strlcat functions don't appear to be in Interpid's glibc...any idea why this might be the case? Is this just an Ubuntu thing, or is it not to be found anywhere in Linuxdom? At school we had "STRLFOO(), NOT STRNFOO(), AND CERTAINLY NOT PLAIN OLD STRFOO(), YOU IDIOTS" beaten into us, and those machines were all running Linux, so maybe the functions were added in after the fact...? Linux normally does not have those functions, because some primary glibc developers believe that they can lead to unnoticed string truncation bugs and are not particularly safer than the *n* functions. Certainly if you use the *n* functions correctly there are no risks of buffer overflows, and it's no harder than using the *l* functions correctly; the *l* variants only cover you if your code mixes usage of the *l* functions and the completely unsafe variants.
|
# ? Feb 21, 2009 06:43 |
|
More on template functions, as the earlier discussion on this page reminded me that I came across this today: What's the purpose of the template<> in this? template<> static const std::string tostr(const std::wstring& s) { return std::string(s.begin(), s.end()); }
|
# ? Feb 21, 2009 10:16 |
|
That code is invalid. (Which is to say it might work, but it's almost certainly not what you want. Use a regular function.) Avenging Dentist fucked around with this message at 10:30 on Feb 21, 2009 |
# ? Feb 21, 2009 10:24 |
|
Dijkstracula posted:"STRLFOO(), NOT STRNFOO(), AND CERTAINLY NOT PLAIN OLD STRFOO(), YOU IDIOTS" What does strlfoo do?
|
# ? Feb 21, 2009 14:56 |
|
I have an enumeration with these values in (something tells me it would chose those values but default anyway, but I didn't want to risk complicating it even more for now).code:
code:
code:
|
# ? Feb 21, 2009 17:25 |
|
Injured Zebra posted:Is there a way I can get input from the keyboard and set the enumeration to that? code:
code:
|
# ? Feb 21, 2009 17:38 |
|
Standish posted:Not directly, no. You could mess with the ASCII codes and do: I'll try that thanks.
|
# ? Feb 21, 2009 17:41 |
|
I've got a question about making your own class. I know I need a header file, and a .cpp file, and I have written both of those out, what I was wondering was, do I put the main part of the program in the same .cpp file or do I just go to add->new etc, and insert the code for the main part of my program there?
|
# ? Feb 22, 2009 19:38 |
|
Do whatever you want.
|
# ? Feb 22, 2009 22:18 |
|
Vandorin posted:I've got a question about making your own class. I know I need a header file, and a .cpp file, and I have written both of those out, what I was wondering was, do I put the main part of the program in the same .cpp file or do I just go to add->new etc, and insert the code for the main part of my program there? The most commonly used pattern I've seen is adding a main.cpp to the project with nothing more than a main function.
|
# ? Feb 22, 2009 23:54 |
|
How do I strip an extension from a file in C? For example, I have a file called "output/1.png". I can use basename to get it to "1.png". I want to remove the .png as well.
|
# ? Feb 23, 2009 03:14 |
|
mistermojo posted:How do I strip an extension from a file in C? Either use index(3) or rindex(3) to find the period, then set it to NUL. You need to decide if you want "foo.bar.baz" to turn in to "foo.bar" (use rindex(3)) or "foo" (use index(3)).
|
# ? Feb 23, 2009 03:20 |
|
ShoulderDaemon posted:Either use index(3) or rindex(3) to find the period, then set it to NUL. You need to decide if you want "foo.bar.baz" to turn in to "foo.bar" (use rindex(3)) or "foo" (use index(3)). index(3) and rindex(3) are both part of strings.h rather than string.h and thus aren't going to be present on a non-POSIX system (even then, both are marked as 'legacy' in POSIX.1-2001). You're better off using something like strchr(3)/strrchr(3) or even strtok(3) if you care about portability (which mistermojo may or may not). e: forgot about strrchr Blotto Skorzany fucked around with this message at 03:50 on Feb 23, 2009 |
# ? Feb 23, 2009 03:46 |
|
strrchr should work, too.
|
# ? Feb 23, 2009 03:49 |
|
In C++ is there any way to do if(x[f][b] == int)? I just need it to know if the place is an integer so that it can run through the statement. Is there any way to do it?[google searches have led nowhere]
|
# ? Feb 23, 2009 13:52 |
|
Cirrus_Alreia posted:In C++ is there any way to do if(x[f][b] == int)? Depending on what x is, you may be looking for function overloading, templates, typeof (not part of the standard) or someone to hit you on the fukken head.
|
# ? Feb 23, 2009 14:03 |
|
Painless posted:Depending on what x is, you may be looking for function overloading, templates, typeof (not part of the standard) or someone to hit you on the fukken head. all I need to know is there some simple way to deduce whether x is of type int.
|
# ? Feb 23, 2009 14:21 |
|
Cirrus_Alreia posted:jesus christ. Check the declaration of x, then.
|
# ? Feb 23, 2009 15:19 |
|
|
# ? Jun 7, 2024 04:09 |
|
Cirrus_Alreia posted:jesus christ. You probably are approaching your problem the wrong way and should be branching out via overloads as was already recommended. If you are very stubborn here or are sure that the functionality you are asking for really is the most elegant solution, you can use BOOST_TYPEOF or make a ghetto typeof facility: code:
That Turkey Story fucked around with this message at 15:39 on Feb 23, 2009 |
# ? Feb 23, 2009 15:37 |