|
Use boost.format. str(boost::format("%5.3f") % x) prints the value of x formatted into a std::string as you would expect from experience with printf. It's type-safe, and there's no need to worry about overrunning a buffer.
|
# ? Apr 13, 2009 02:32 |
|
|
# ? Apr 29, 2024 18:27 |
|
Is there any online guides to learn c++ that you can recommend? I apologize if this question already has been asked.
|
# ? Apr 13, 2009 18:17 |
|
If you're serious about wanting to learn the language, you should buy a book instead of relying on lovely and outdated web tutorials. See the first post for recommendations.
|
# ? Apr 13, 2009 19:09 |
|
Is there any way to do have two functions identical, except for the order of default-valued parameters of different types?code:
|
# ? Apr 13, 2009 22:10 |
|
I am assuming you mean for both of the functions to be named foo because there's nothing wrong with your code now (except that you can't return a value from a void function, and that your second definition has an extra semicolon). In that case, foo(1) is ambiguous. There are lots of ways to resolve this, but the real answer is that you probably shouldn't be using default parameters like that. Any more than one default per function is just annoying to use. Boost.Parameter probably resolves the core issue you have, at the expense of some hilarious templates.
|
# ? Apr 13, 2009 22:34 |
|
I'd like to have a vector class that has 3 floats. I'd like to be able to access them either as an array: myvec.val[0] or as individual members: myvec.x. Is there a way to do this with unions or something?
|
# ? Apr 13, 2009 23:50 |
|
You could always do:code:
|
# ? Apr 13, 2009 23:54 |
|
code:
edit: VV Suck it AD :P No. you just sucked off the trailing ; :P Zakalwe fucked around with this message at 00:00 on Apr 14, 2009 |
# ? Apr 13, 2009 23:56 |
|
^^ At least mine compiles. Contero posted:I'd like to have a vector class that has 3 floats. I'd like to be able to access them either as an array: myvec.val[0] or as individual members: myvec.x. Is there a way to do this with unions or something? Yes, through non-standard extensions supported in gcc and MSVC (stolen verbatim from one of my projects): code:
|
# ? Apr 13, 2009 23:57 |
|
Sweet. Thanks guys.
|
# ? Apr 14, 2009 00:09 |
|
Avenging Dentist posted:I am assuming you mean for both of the functions to be named foo because there's nothing wrong with your code now (except that you can't return a value from a void function, and that your second definition has an extra semicolon). Yes, yes, and those aren't hilarious, they're kinda hideous. (Not as bad as the same for policy class templates!) It technically resolves the core issue, but not nicely enough to warrant use. Thanks for the info, tho.
|
# ? Apr 14, 2009 01:37 |
|
I have an SDL app with loads of bitmaps that I want to to include in the .exe and I'm using Dev-C++. Does anyone know where I can find a simple guide to writing resource files?
|
# ? Apr 14, 2009 05:10 |
|
Please don't use Dev-C++, it is an absolutely terrible IDE. If you're hell-bent on not using Visual Studio, use windres to compile the .rc files.
|
# ? Apr 14, 2009 05:14 |
|
Can anyone tell me what the problem with this code is?code:
9 [sig] extest 236 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped)
|
# ? Apr 14, 2009 08:20 |
|
Madoushi posted:Can anyone tell me what the problem with this code is? What do you expect it to do? edit: what does the backtrace from the core file tell you?
|
# ? Apr 14, 2009 08:44 |
|
I'm trying to make a simple roguelike on windows using Visual Studio 2008. I want to use pdcurses for console manipulation. I have the .h files, the .lib, and the .dll. I added the .h files and the .lib to the project preferences, but how to I get it to use the .dll? currently all I have is: code:
code:
|
# ? Apr 14, 2009 19:02 |
|
If you're getting a link error at build time, it's not because the DLL can't be found, it's because you're not linking with the lib. Did you add the lib's path to the "additional places to look for libraries"* setting in Project Preferences, in addition to adding the name of the lib to "additional library dependencies"? * Something like that, I can never remember
|
# ? Apr 14, 2009 19:21 |
|
I believe so: Click here for the full 972x789 image.
|
# ? Apr 14, 2009 19:39 |
|
Did you explicitly add the library to the Linker -> Input properties?
|
# ? Apr 14, 2009 20:35 |
|
Go to linker->input and add the .lib to Additional Dependencies.
|
# ? Apr 14, 2009 22:10 |
|
I've been playing with this for a good hour and a half straight and I'm getting no luck. I've put all of the libraries straight into the visual studio 9 folder in the appropriate places even. Maybe I'll just abandon using this and find some other way to control the console.
|
# ? Apr 14, 2009 23:44 |
|
All you should need are curses.lib in Configuration Properties > C/C++ > Linker > Input > Additional Dependencies, and the path in Linker > General > Additional Library Directories. I can think of three things that are wrong, in order of rapidly decreasing likelihood: 1) The path needs quotes around it because it has spaces, 2) initscr() isn't a curses function and you didn't define it yourself, 3) curses.lib doesn't reference initscr().
|
# ? Apr 15, 2009 00:00 |
|
Bah, I'll just let it go. I recently found libtcod which does everything that I want and more, and I got it running with no problems. Thanks for the help though.
|
# ? Apr 15, 2009 01:13 |
I think I've been coding too long and I'm going crazy but for some reason this isn't workingcode:
First-chance exception at 0x777f0ab0 in mapmaker.exe: 0xC0000005: Access violation reading location 0x00d43c42. First-chance exception at 0x75b7f35f in mapmaker.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0017dfd0.. Unhandled exception at 0x75b7f35f in mapmaker.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0017dfd0.. or a message about heap corruption. It's almost exactly the same as the cplusplus.com example std::queue usage and it's making me feel like an idiot that I can't use a drat stl container right.
|
|
# ? Apr 15, 2009 05:54 |
|
huge sesh posted:I think I've been coding too long and I'm going crazy but for some reason this isn't working Works fine for me: http://codepad.org/9JxpwM65
|
# ? Apr 15, 2009 07:02 |
|
Is that all your program is doing? Or are you allocating lots of memory elsewhere? Did you disable your page file or something wacky like that? Do you get the same error when you try to use other containers, like vector?
|
# ? Apr 15, 2009 15:30 |
|
I use Code::Blocks just because it's pretty straight forward. I found Visual Studio to be overly complicated.
|
# ? Apr 15, 2009 17:13 |
|
Mach Won posted:I use Code::Blocks just because it's pretty straight forward. I found Visual Studio to be overly complicated. The code you posted is fine, there'll be something that's corrupting the heap preceding it.
|
# ? Apr 15, 2009 17:36 |
|
I'm not all that familiar with C, but while working on a grad-level assignment came across something weird. The assignment was filling in a couple dummied out functions in a c program and we were given a bunch of pre-written functions to call. The source code was all written by the professor in a format I had never seen:code:
code:
code:
|
# ? Apr 15, 2009 17:42 |
|
Plank Walker posted:I'm not all that familiar with C, but while working on a grad-level assignment came across something weird. The assignment was filling in a couple dummied out functions in a c program and we were given a bunch of pre-written functions to call. The source code was all written by the professor in a format I had never seen: Your professor is using traditional C. If I remember correctly, float parameters are automatically converted to doubles in some cases. Is the procedure defined before any code that calls it?
|
# ? Apr 15, 2009 18:03 |
|
Janin posted:Your professor is using traditional C. If I remember correctly, float parameters are automatically converted to doubles in some cases. Is the procedure defined before any code that calls it? The function prototype is written as somefunction(int, float);. I've sent it the actual parameter as code:
|
# ? Apr 15, 2009 18:36 |
|
Janin posted:Your professor is using traditional C.
|
# ? Apr 15, 2009 18:43 |
|
Plank Walker posted:The function prototype is written as somefunction(int, float);. I've sent it the actual parameter as Mustach posted:"K&R" C is not a tradition. I would be suspicious of the quality of any compiler that quietly accepts it, and extremely suspicious of the quality of any man that willingly writes in it.
|
# ? Apr 15, 2009 19:11 |
|
Yep I'm cryin' my eyes out here.
|
# ? Apr 15, 2009 19:20 |
|
Does anyone know of any function or other way to have a program resize the terminal window it's running in?
|
# ? Apr 15, 2009 19:23 |
|
Glasgerion posted:Does anyone know of any function or other way to have a program resize the terminal window it's running in? That doesn't sound very portable to you, now does it?
|
# ? Apr 15, 2009 19:34 |
|
Ugg boots posted:That doesn't sound very portable to you, now does it? Are you saying there's no good way to do it?
|
# ? Apr 15, 2009 20:12 |
Glasgerion posted:Does anyone know of any function or other way to have a program resize the terminal window it's running in? libncurses?
|
|
# ? Apr 15, 2009 20:31 |
Mustach posted:Is that all your program is doing? Or are you allocating lots of memory elsewhere? Did you disable your page file or something wacky like that? Do you get the same error when you try to use other containers, like vector? It's certainly not all the program's doing but it's really not that complicated. I don't allocate that much memory, page file is normal. std::vector works fine elsewhere in the program. I guess I'll look around for possible heap corruption. Just seems weird that it would happen every time.
|
|
# ? Apr 15, 2009 20:34 |
|
|
# ? Apr 29, 2024 18:27 |
|
Glasgerion posted:Does anyone know of any function or other way to have a program resize the terminal window it's running in? Just for grins, let's assume you're using Linux with the Metacity WM. You might be able to pull it off like this: code:
Like huge sesh said, you might also be able to leverage ncurses's resizeterm() function. It all depends on what you mean by "resize the terminal window" and what environment you're working with.
|
# ? Apr 15, 2009 20:46 |