![how to convert a file into map in c++ how to convert a file into map in c++](https://windows-cdn.softpedia.com/screenshots/bin2img-converter_3.png)
So unless you have a specific requirement for the save data to be readable, I would suggest simplifying the code a lot by not saving / reading in a less readable but simpler format. As you said, you could also use a database but then it would be much less flexible then a simple file. If your need is strictly to pass around data, such as save data somewhere and then load the data somewhere else, then the specific format of the saved data should not matter. So, keep it up! And good luck with your projects. Overall, the code is generally good and clean. If you switched to string_view you would gain an enormous performance increase. But as noted earlier, you are re-copying the string over and over and over as you parse it, so that would not help.
![how to convert a file into map in c++ how to convert a file into map in c++](https://windows-cdn.softpedia.com/screenshots/XML-plus-XSL_1.png)
It would be better if the delim and the input were passed as string_view, so it could handle a wider variety of actual argument types efficiently. These helpers would be private member functions. If you had an object that maintained the dictionary and a member function to accept input, you could call it more than once and easily have a single dictionary that spanned multiple lines of input, or was split across separate sources (like a default string or environment string in addition to the explicit parameters). In particular, you are limited to reading the entire record with one string submission. But, it's also unusual to make something like this a single function call rather than an object with several separate calls, too. That's something we don't see a lot of in C++ yet. It's interesting how you used lambdas for helper functions, to prevent having to pass additional parameters into (separate) helper functions. What do you do if there's a syntax error in the input? More traditionally, parsing would be done by advancing an iterator over the input, not manipulating the owning container (the string in your case). It just adjusts a pointer and does not have to keep re-copying the entire string after reading each token. It has a remove_prefix that is perfect for this kind of scanning from the front. S += white // necessary if s doesn't contain trailing spacesĪuto removeLeading = () The C++ code #include Ĭonst std::string& white = " \n\t\v\r\f" ) Where MAX_INIT_WORD is a maximal prefix of S that doesn't contain WP or D. Remove first WP characters if any ( until the first non-WP is met) from S Remove first WP characters if any (until the first non-WP is met) from S Note that one line may contain several KEY- VALUE pairs. KEY, VALUE - WORDs : which contain neither a whitespace character nor the delimiter one Where WPs - any number of whitespace charactersĭ - delimiter character, separates KEY and VALUE Where each line is (must be) of the form : Type : ORDER_TYPE_SELL_STOP State. Ticket: 8 Type: ORDER_TYPE_BUY_STOP State: ORDER_STATE_CANCELED Reason: ORDER_REASON_EXPERT Start: 1509671100000 End: 1509732000000 Ticket: 7 Type: ORDER_TYPE_BUY_STOP State: ORDER_STATE_CANCELED Reason: ORDER_REASON_EXPERT Start: 1509624000000 End: 1509638920000
![how to convert a file into map in c++ how to convert a file into map in c++](https://www.javelin-tech.com/blog/wp-content/uploads/2013/03/photo-2-847x1024.jpg)
Ticket: 6 Type: ORDER_TYPE_SELL_STOP State: ORDER_STATE_CANCELED Reason: ORDER_REASON_EXPERT Start: 1508522400000 End: 1508524540000 Ticket: 4 Type: ORDER_TYPE_SELL_STOP State: ORDER_STATE_FILLED Reason: ORDER_REASON_EXPERT Start: 1508375100000 End: 1508389780000 Ticket: 3 Type: ORDER_TYPE_BUY_STOP State: ORDER_STATE_CANCELED Reason: ORDER_REASON_EXPERT Start: 1507723200000 End: 1507760140000 So typical content of such a file (real example so the alignment) : Ticket: 2 Type: ORDER_TYPE_SELL_STOP State: ORDER_STATE_CANCELED Reason: ORDER_REASON_EXPERT Start: 1507032000000 End: 1507140000000
HOW TO CONVERT A FILE INTO MAP IN C++ HOW TO
Though the proper way (probably) to do this would be to use databases (which I don't know how to work with) I chose writing the data to a simple text file which in turn is being read and parsed when needed. Recently I needed a way to transport data from one environment to another.