|
Its called fcvt_r()
|
# ? Nov 21, 2014 20:18 |
|
|
# ? Jun 1, 2024 18:28 |
|
I'm having a bit of information overload with a work project, and could use some guidance. Note: I'm a total beginner at with C++ and programming in general. I'd trying to write a Windows program that will accept a series command line arguments, and based off those it will display video in the correct format (I work for a company that makes frame grabber products for medical devices) in a window. I'm using Visual Studio 2010, and the program will be run on Windows 7 and maybe 8 using the command prompt. The problem that I'm running into is that I keep reading various articles that say I should use GetCommandLine(), other say I should use __argv/__argc, some say lpCmdLine, and others say I should use a third party library like Boost.program_options() or getopt. __argv works in my testing, but I keep reading that I shouldn't use __argv but I having trouble finding out why. Also, should I be using ASCII or Unicode? Does it matter? Edit: I should have said, Visual Studio generated the program entrance as: code:
I guess what Im asking is what would be the best way to capture the command Iine arguments and aprse them from there. Thanks Risket fucked around with this message at 17:23 on Nov 23, 2014 |
# ? Nov 23, 2014 17:17 |
Since you're using WinMain() as entry point, I assume you're writing a windowed application, as opposed to a console application. Windows passes command line arguments differently from Unix systems; where Unix passes the commandline as an array of strings, Windows passes it as a single long string without separation. However Windows does provide a function that can do a standard split into arguments. C++ code:
|
|
# ? Nov 23, 2014 17:32 |
|
nielsm posted:You should definitely use Unicode on Windows. Writing programs to the ANSI APIs is deprecated, is almost guaranteed to cause bugs if you use the program on a different language version of Windows than what you're developing for, and locks you out of some newer APIs altogether.
|
# ? Nov 23, 2014 17:39 |
|
nielsm posted:Since you're using WinMain() as entry point, I assume you're writing a windowed application, as opposed to a console application. Alternatively, the application is supposed to be a console application, and the project was just set up wrong. Risket, when you created your project in Visual Studio, did you create an empty console project, or some other project type? In a console project, your entry point would be called main, and it would have argc and argv parameters for you to use. (getopt and Boost.program_options are helpers for parsing argv out, but if you're a novice, it's better to just do it yourself so you have fewer things to think about.)
|
# ? Nov 23, 2014 17:40 |
|
Risket posted:I'm having a bit of information overload with a work project, and could use some guidance. _argv and __argc are globals defined in stdlib.h by VC, however they are not standard definitions and should be avoided if possible. You could parse lpCmdLine yourself or use GetCommandLineW and CommandLineToArgvW to parse the command line into separate strings. I don't know why, but CommandLineToArgvW expects a non-empty string, which GetCommandLineW will return as the command line will always contain the program name, and thus lpCmdLine should not be passed to it. edit: Just to followup on what I said above about not using the globals is for the WIN GUI eentry point. If you have int main(int argc, char ** argv) as your function prototype then use the argc and argv inputs. asur fucked around with this message at 17:43 on Nov 23, 2014 |
# ? Nov 23, 2014 17:41 |
roomforthetuna posted:Aren't the W versions of functions a horrible kind of Unicode? Is there no UTF-8 for Windows GUI stuff? It's UTF-16, and it's the only way to talk Unicode to Windows. It's also what it uses internally. As long as you don't try to chop up strings by characters but just treat them as opaque values that can be manipulated by library functions, you should be fine. (There's UTF-16 surrogate pairs, and then there's the much be devious cases of multiple codepoints affecting each other in complex scripts. It's usually only relevant when you're actually working with natural language text.) Sure, you can use UTF-8 in Windows software, but not for calling Win32 APIs. Theoretically it could be possible to set the ANSI-codepage for your process to 65001 which is UTF-8 and use the ANSI API with UTF-8 strings, but Microsoft doesn't test that so it doesn't actually work.
|
|
# ? Nov 23, 2014 17:55 |
|
GrumpyDoctor posted:Alternatively, the application is supposed to be a console application, and the project was just set up wrong. Risket, when you created your project in Visual Studio, did you create an empty console project, or some other project type? In a console project, your entry point would be called main, and it would have argc and argv parameters for you to use. (getopt and Boost.program_options are helpers for parsing argv out, but if you're a novice, it's better to just do it yourself so you have fewer things to think about.) Edit: I'll just use Unicode and figure out how to use GetCommandLine(). Thanks guys. Risket fucked around with this message at 18:01 on Nov 23, 2014 |
# ? Nov 23, 2014 17:58 |
Risket posted:Edit: I'll just use Unicode and figure out how to use GetCommandLine(). Thanks guys. The code snippet I posted above shows exactly how you should use GetCommandLineW(), together with CommandLineToArgvW(), to get something you can work with without too much hassle.
|
|
# ? Nov 23, 2014 18:05 |
|
nielsm posted:The code snippet I posted above shows exactly how you should use GetCommandLineW(), together with CommandLineToArgvW(), to get something you can work with without too much hassle.
|
# ? Nov 23, 2014 18:47 |
|
Risket posted:I'm using Visual Studio 2010, and the program will be run on Windows 7 and maybe 8 using the command prompt. If you run a GUI program from the command prompt, the command prompt will not wait for it to terminate. If it's important that the command prompt knows when your program terminates (for example if it has to be called from a batch script), then compile it as a console application. Yes, console applications can create windows Risket posted:__argv works in my testing, but I keep reading that I shouldn't use __argv but I having trouble finding out why. It's non-standard as you can tell from the double underscore, but who cares. Me, I would use wmain (int wmain(int argc, wchar_t **argv)), and then manually set the program as a GUI program in the linker settings (look in the project's settings, look for "subsystem" under linker settings), but WinMain with __argc and __argv is perfectly fine. Not sure if you really need getopt/Boost.ProgramOptions, depends on how complex your command line arguments are Risket posted:Also, should I be using ASCII or Unicode? Does it matter? Use Unicode. I don't know if it matters to your particular application, but Unicode is pretty much standard everywhere nowadays If you need to interact with third party Unicode libraries, Windows Unicode strings are in UTF-16 format and need to be converted if you need UTF-8 Risket posted:Edit: I should have said, Visual Studio generated the program entrance as: All arguments to WinMain are data you can get from GetModuleHandle, GetStartupInfo or GetCommandLine. There's nothing magic to them, and the WinMain parameters are only kept for backwards compatibility with 16 bit Windows (where hPrevInstance could be something other than NULL for example), so don't read too much into them Risket posted:I guess what Im asking is what would be the best way to capture the command Iine arguments and aprse them from there. Get them with argc/argv or __argc/__argv, parse them however you like I wouldn't use CommandLineToArgvW because it uselessly duplicates work the C/C++ runtime library already does roomforthetuna posted:Aren't the W versions of functions a horrible kind of Unicode? UTF-16, it's alright roomforthetuna posted:Is there no UTF-8 for Windows GUI stuff? No and it's a little silly, but that's how it is
|
# ? Nov 23, 2014 20:11 |
|
hackbunny posted:If you run a GUI program from the command prompt, the command prompt will not wait for it to terminate. If it's important that the command prompt knows when your program terminates (for example if it has to be called from a batch script), then compile it as a console application. Yes, console applications can create windows And here I was hoping that this would be a small project that would last a couple of days.
|
# ? Nov 23, 2014 20:26 |
|
Hello again COC, For the past couple of days I have been trying to use libCurl to log into a website ( draftkings.com ) and try to scrape the contest list. I am pounding my head on the wall as to why my curl requests are not being accepted. The following is a summary of my code ( mostly just an example from the curl website ). Am I using curl wrong? code:
|
# ? Nov 24, 2014 04:42 |
|
Is there a plain-English, near retard level explanation for how to use the Boost Graph Library to put together a directed graph with weighted edges out there anywhere, and, if so, may I read it?
|
# ? Nov 24, 2014 10:20 |
|
FearIt posted:For the past couple of days I have been trying to use libCurl to log into a website ( draftkings.com ) and try to scrape the contest list. I am pounding my head on the wall as to why my curl requests are not being accepted. The following is a summary of my code ( mostly just an example from the curl website ). Am I using curl wrong? What do you mean by your requests aren't being accepted? What is the error you get, and are you sure that http post actually works in the first place (i.e. when you aren't trying to do it in libcurl)?
|
# ? Nov 24, 2014 17:23 |
|
astr0man posted:What do you mean by your requests aren't being accepted? What is the error you get, and are you sure that http post actually works in the first place (i.e. when you aren't trying to do it in libcurl)? I believed that a correct POST would result in the return data to contain account specific information. My test for success involves looking for my current account balance, instead looking over the return, I see a login prompt again. It might indeed be that the post does not work, I gathered the filenames from the <form> block and am pretty sure I'm getting it right,, but I may be wrong.
|
# ? Nov 25, 2014 05:25 |
|
FearIt posted:I believed that a correct POST would result in the return data to contain account specific information. My test for success involves looking for my current account balance, instead looking over the return, I see a login prompt again. It might indeed be that the post does not work, I gathered the filenames from the <form> block and am pretty sure I'm getting it right,, but I may be wrong.
|
# ? Nov 25, 2014 08:45 |
|
You may need to appropriate encoding header (Content-Type: application/x-www-form-urlencoded). Also for heaven's sake, you're not really turning off verification of peer's SSL certificate, are you?
OddObserver fucked around with this message at 14:02 on Nov 25, 2014 |
# ? Nov 25, 2014 13:59 |
|
I work for a company that manufacturers frame grabber boards. (http://en.wikipedia.org/wiki/Frame_grabber) As I said earlier, I'm trying to write an application that will take a series of command line arguments to accept the video format and input that is being sent to the board, and configure the device to accept that video. Now, thanks to the help I got earlier, I am able get the command line arguments, and parse them using std::find. However, the problem is that there are 57 different video formats/resolutions/etc... that could be used. The video formats are specified in a header file, and are GUIDs. You select the GUID to use, then insert it as a referenced function parameter. Here is an example: code:
Please note that I'm pretty much a beginner at this... Thanks
|
# ? Nov 25, 2014 17:44 |
Make a static lookup-table mapping between sensible strings and the GUIDs.C++ code:
C++ code:
|
|
# ? Nov 25, 2014 17:58 |
|
nielsm posted:Make a static lookup-table mapping between sensible strings and the GUIDs. Thank you very much!
|
# ? Nov 25, 2014 18:16 |
|
Risket posted:I have no idea what half this poo poo is, but I'm going to Google the hell out of all of it to figure it out. Basically you're creating a map ahead of time between friendly-name <-> guid so you can just directly pull out the data you want. That being said I'm curious why he's not just making a std::unordered_map<> (newbie as well)?
|
# ? Nov 25, 2014 18:26 |
|
Mr. Crow posted:Basically you're creating a map ahead of time between friendly-name <-> guid so you can just directly pull out the data you want.
|
# ? Nov 25, 2014 18:37 |
Mr. Crow posted:Basically you're creating a map ahead of time between friendly-name <-> guid so you can just directly pull out the data you want. You probably could do that, but it'd be uncomfortable syntax-wise if the compiler doesn't fully support initializer-lists. As far as I understand, Risket is using MSVC where that still isn't such a good idea yet. But I think it should look something like this: C++ code:
|
|
# ? Nov 25, 2014 18:51 |
|
Risket posted:What is the difference? Is there a problem with what he posted? nielsm's suggestion (a normal array) has no complexity in the setup at the expense of a linear search at runtime, which in practice for a 57 element list searched once at program startup is not a problem. Mr. Crow's suggestion (a std::unordered_map<>) trades some complexity in the setup for fast lookup times, since std::unordered_map<> is required to have amortized constant time complexity and in practice ends up being a hash table. This is what you'd want to do if you search your list frequently or had thousands of elements instead of just 57.
|
# ? Nov 25, 2014 18:56 |
|
nielsm posted:You probably could do that, but it'd be uncomfortable syntax-wise if the compiler doesn't fully support initializer-lists. As far as I understand, Risket is using MSVC where that still isn't such a good idea yet.
|
# ? Nov 25, 2014 18:57 |
|
nielsm posted:You probably could do that, but it'd be uncomfortable syntax-wise if the compiler doesn't fully support initializer-lists. As far as I understand, Risket is using MSVC where that still isn't such a good idea yet. This is a function declaration, right? Risket fucked around with this message at 19:48 on Nov 25, 2014 |
# ? Nov 25, 2014 19:46 |
|
Risket posted:I'm getting an "expected a declaration" error on this first curly brace. Try adding an equals sign. If that doesn't work, I don't know.
|
# ? Nov 25, 2014 19:48 |
|
Risket posted:I'm getting an "expected a declaration" error on this first curly brace. http://stackoverflow.com/questions/12654394/initializer-list-not-working-with-vector-in-visual-studio-2012 Initializer lists are only supported in VS2013, if you're using VS. Otherwise the first post has the correct syntax.
|
# ? Nov 25, 2014 19:57 |
I think you actually need the upcoming VC 2015 for full initializer list support, there are some bugs with it in 2013 still.
|
|
# ? Nov 25, 2014 20:13 |
|
nielsm posted:
Now I'm getting an "expression must have a class type" Intellisense error on every guid_name.name/guid instance following the declaration in the for loop. Following compile: error C2228: left of '.guid' must have class/struct/union type is 'const NamedGuid *' did you intend to use '->' instead? Risket fucked around with this message at 20:27 on Nov 25, 2014 |
# ? Nov 25, 2014 20:23 |
Risket posted:I apologize for making GBS threads up this thread with lots of questions, but I don't know enough to know the correct term to search for. Sorry, my fault there for typing without thinking. Should all be guid_name->name and guid_name->guid for dereferencing member lookup, i.e. arrow instead of dot.
|
|
# ? Nov 25, 2014 20:25 |
|
nielsm posted:Sorry, my fault there for typing without thinking.
|
# ? Nov 25, 2014 20:33 |
|
I'm working on doing part-of-speech tagging with the Viterbi algorithm. We've been given a table of word/tag counts: We also have a table of bigram probabilities (incomplete): I need to be able to grab a word from an input sentence and look up counts and probabilities from these two tables. I can set up 2-d arrays for the tables, that's no problem, but getting the indices into those tables is proving problematic. I thought of making enums for the words and tags, but that would leave me making a bunch of if/then statements to figure out which word is being looked at. Is there a standard/normal way to do something like this?
|
# ? Nov 26, 2014 14:48 |
|
hooah posted:I need to be able to grab a word from an input sentence and look up counts and probabilities from these two tables. I can set up 2-d arrays for the tables, that's no problem, but getting the indices into those tables is proving problematic. I thought of making enums for the words and tags, but that would leave me making a bunch of if/then statements to figure out which word is being looked at. Is there a standard/normal way to do something like this? You can use a hash table (unordered_map, C++11 only) or a map for this. For the map, your keys could be strings representing each of the possible words or tags.
|
# ? Nov 26, 2014 15:06 |
|
giogadi posted:You can use a hash table (unordered_map, C++11 only) or a map for this. For the map, your keys could be strings representing each of the possible words or tags. Y'know, I'd done this for the words, then for some reason my brain went "That won't work for the tags!". Thank you!
|
# ? Nov 26, 2014 18:06 |
|
roomforthetuna posted:Chrome has some pretty cool debug-aid features that include being able to examine the full request that was sent, which you could use as a much more reliable and convenient way to get POST data than trying to figure out what it will be by looking at HTML forms. This provided exactly what I was looking for. I mimicked the rest of the POST data and got the success condition. Thanks!
|
# ? Nov 26, 2014 23:39 |
|
I'm having an issue getting some code I wrote on Linux working on OSX.. The following code snippet sums it up. Client: code:
code:
Linux server and OSX client: Done in milliseconds. OSX server and Linux/OSX client: I don't know how long, probably an hour. I've controlled for TCP_NODELAY and blocking, and a blocking socket in Linux and OSX seem to behave completely differently. A recv() call for a socket spawned from an accept() call seems to go really slow on OSX, while it's fast on Linux. In OSX you can set the socket to nonblocking, but then recv() and send() start to return -1 occasionally. I can set the OSX socket to nonblocking mode, catch those -1 returns and retry until I've sent all my data; I guess this is what I'm supposed to do then? More to the point, is there some good, cross-platform wrapper for native socket functions, which all seem to behave differently in unexpected ways? Or do I just bandage it up with preprocessor macros? The Gay Bean fucked around with this message at 17:26 on Nov 28, 2014 |
# ? Nov 28, 2014 17:18 |
|
The Gay Bean posted:Linux client and server: done in milliseconds. You could use Wireshark to see what's actually going on.
|
# ? Nov 28, 2014 17:30 |
|
|
# ? Jun 1, 2024 18:28 |
|
With printf, can I specify the number of exponent digits? I'm not going to have anything with more than a 2-digit exponent and I already formatted other output based on that assumption.
|
# ? Nov 28, 2014 18:01 |