Rewrite txt file into other encoding [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a problem. I want to rewrite txt file into other txt file, but with other encoding. I must implement conversion to Unicode, iso-8859 and windows-1250.
I must write it in c++.
Can anyone help me with this topic? How to start coding this?
Best regards!

Windows is perfectly capable of doing string conversions for you. Read data from the source file and pass it to MultiByteToWideChar specifying the source codepage, then pass that output to WideCharToMultiByte specifying the target codepage and write that output to the target file.
BTW, next question state up front that you're working on Windows only. Don't put useful information like that in a comment.

I would start by getting a good in-depth knowledge of this encoding formats, I would create some encoding conversion tables, and convert byte by byte. Also, it sounds like you are going to be dealing with different operating systems, so keep an eye out for endianness.
Here's a good link to get you started Encoding for Programmers.
EDT#1: Here is another link that goes a little more in depth on the subject of character encoding in windows. Here you can find functions and macros that can help you building your application.

Related

How to properly store an array of constant data? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
My question is particularly pointed towards what's neat and efficient and won't get me made fun of as a programmer.
So basically I want to store a huge file of names of PNGS. So of course I'd use an array of strings in order to store all those names. But my question is should I store these strings in something like a binary file? Or should I just put them straight onto the script? I personally hate the idea of using a text file to store them but what do I know.
If I were to put them on a script then it would look something like this:
const std::string tileFile[textureAmount] ={
"Grass.png",
"Dirt.png"
};
But this just looks really stupid to me for some reason. How would one handle a situation like this more professionally?
A character is 1 byte, whether you write a text file or a binary file. The only savings would be if you did some encoding or compression to it, and text does compress nicely since not all the bits in the chars are usually used.
But one pragmatic rule for programming is, "remember the power of plain text". Binary is nice, but if you don't need it, don't use it. Text is easier to work with, to read, to understand when it is corrupted, to use with other tools, and so on. If you can map the data into memory, use binary. If you're going to gzip it or something like that, use binary. If you're just storing the data and it's not excessively big, then I'd recommend a nice, easily parsed text file.
And don't feel ashamed of it. :)

Is my company doing this right, sharing data between exes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
First off, my company is into power grid, not IT, so software is kinda a secondary role here.
I work on a power system simulation software, very old code base in C++ with MFC, like 15 years old. What we do is take large amounts of data, ~100,000 floating point values then format and write to a text file (most of the code actually uses the C FILE structure to do this). Then, it's read by a separate engine exe which computes the electrical algorithm (Electrical algorithms are mostly numeric solutions of system of diffn equations) and then writes back huge amount of data to another text file, which we read and update the UI.
My question is, is this how it should be done? It there a way to skip writing into the text file and directly pass the data to the exes?
exes are called using CreateProcess() MFC function.
EDIT::
Sorry, site won't let me comment.
#Vlad Feinstein Well, yes, it's like a Ladder. A thing called load flow solves power flow through the lines, which in turn will be used to find stability of the systems, which in turn for overvoltage ect. It's huge, the UI is million+ lines of code, engine exes another million maybe.
Doesn't MFC already implement IPC using Dynamic Data Exchange? I can pass strings to another process's PreTranslateMessage() func. A scaled up version of that?
There is no such a thing as "should be done as ..." there are multiple methods to do IPC and while the method you describe might not be the fastest, it is a viable solution nevertheless. If the performance doesn't bother you in this particular case you should not bother with modifying it. It is exactly the case where the phrase "if it ain't broke, don't fix it" applies.
Probably, you would not want to make any new IPC in the application that way, though.

Implementation of C string functions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to know how the string manipulation functions are implemented internally so I can figure out their performance. Is there a way to find this out?
I'm talking about null-terminated c strings (arrays of chars) and the related functions (strcat and such) in C++, if that has anything to do with it.
Is there a way to find this out?
Use the source, Luke
The sources for GNU libc string functions are easily viewable in the Git repository
You can also look at other free software or open source C libraries, such as newlib, FreeBSD, NetBSD, OpenBSD, OpenSolaris etc.
if your whole purpose is to figure out the performance I don't think you need to know how it is implemented. You can feed in different data and come up with a graph and compare how the functions performed.
But if you need to study how those functions are implemented, then there is always the source code, which you can get from the internet for different C++ compilers( Not all compilers though).

How to approach a C++ parser [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am wanting to have a go at a C++ parser for a formatter I am making.
You can obviously open a file and use getline(..) or get(), is this reasonable way of starting things off and then working out a system using vector arrays and hence creating loads of arrays and somehow structuring out and processing what you are doing from there. For example say I wanted to find ever function in a source file, all functions have the common syntax, "(){" once whitespace has been removed, so do you just look for common delimeters to parse out the sections into arrays. I suppose I will learn as I go.
Or I also assume there are tried and tested ways of doing this, and I would likley just be reinventing the wheel as they say.
C++ is a language that is quite hard to parse in the first place. So if you want anything other that really trivial C++ code to be "understood" by your parser, you are definitely better off starting with an existing product.
The Clang frontend library would perhaps be a good starting point.
There are also a number of "source to source" conversion examples based on clang. Here's one of them: http://eli.thegreenplace.net/2012/06/08/basic-source-to-source-transformation-with-clang/

structure reading C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following problem:
I have a configuration file that consists a description of fields , which I read it and then parse it. I want to move it into the code to compile it inside.
How would you do that as bug structure ??? or else ?
Thanks
I wouldn't move it into the code, I'd leave the configuration file as a configuration file.
If you really must do this, you can just embed the file as a string resource into the application and use that - that way you'd change only a minimal amount of existing code. The way you do this depends upon your platform.
If thats not feasible (for whatever reason) I'd set up a single configuration class / namespace to contain all the values.
It's not very clear what are you exactly asking.
If you are looking for on-the-fly code execution (like eval() function in some languages), then there is no such thing in C++. It's not an interpreted language which can be read and executed line-by-line, it needs to be compiled every time code changes. While it technically is possible to write self-changing code, it's probably not worth the effort.