Concerning Converting Text file to Binary File c++ - c++

I've been at it all night just trying to get a simple program to read in a text file and then copy it/write it back into a binary format.
My code looped through the text doc, got the data, put it in the buffer and wrote it back out. Heck I even hard coded the data I wanted to be written out in binary.
I used fstream, ofstream, example: fp1.open("student.dat",ios::binary);
and was reading up on several different sites such as:
http://www.functionx.com/cpp/articles/serialization.htm
http://www.cppforschool.com/tutorial/files2.html
and I had working code, but when I open the .bin file in my Notepad++ I saw that my text data still looked like text and wasn't really 'converted' over to any hexdecimal format, or anything really. Numbers were, and I double checked to see if they were accurate by y'know, a little website where you can type in the number and it spits out the hex.
I was so fed up as to why my text wasn't converting that I destroyed all my code and tried to start over. *hence the lack of examples"
So, my question, finally is, why wasn't the text changing in any way, is this normal for a binary file and using this method? I've even used pre-made coding examples and it all came out the same way. Am I just expecting it to all look like 1's and 0's and really it's not and it was all really working?
My main project is to convert an .OBJ file to binary data, but really how should I be looking at this? How should this binary file look?
Any advice would be greatly appreciated!!!
Thank you!

I was just using Chars and string and wasn't seeing a difference. Once I started using other data types, it became apparent that there was a change. I understand that .OBJ and .txt are binary file types, i just expected a bigger change. I used cplusplus.com and reviewed what I needed to know more of. Thank you for trying to help I guess!

Related

How to convert .trc file type to text file using C++?

I have got a trace file that is binary in nature. I want to convert it to a text file and convert the data inside it to decimal form. I mean I am not sure, how to do this. This .trc file contains data in the form of telegrams and I want to extract particular kind of telegram and save them in text file which is readable in nature. I have to do all of this using C++.
Do you suggest any other language for it or does anyone has any idea about doing this in C++?
Binary trace files are usually encoded in proprietary formats. And there are applications or profilers specifically built to parse them.
Unless you know the file format, the only way to decode it is through reverse engineering. And in most cases it's not worth the effort.
Try to find documentation about it. Or maybe an application or utility that loads the file and exports data that is easier to read.
In case you are speaking about .trc binary files from Teledyne Lecroy Oscilloscopes, I would suggest to any of the following libraries out there for that:
https://pypi.org/project/lecroyparser/
https://github.com/jneer/lecroy-reader
https://github.com/yetifrisstlama/readTrc
https://igit.ific.uv.es/ferhue/lecroyparser

Searching .csv file and returning all lines with a specific string c++

Sorry this is my first post on here. I am very new to c++. I am currently working on a small project which requires reading data from a .csv file, searching for specific words and then writing all the lines that contain the specific word to they're own .csv file. I will be honest and say I am out of my depth when it comes to classes etc which is why I am asking you good people on here if you would have or know of any examples of this type of problem for me to try to understand it.
Thanks for anything at all!
Jay

Save File Encryption in Bitcode

I hope that title isn't misleading; part of the problem I'm having is I don't know how to ask the right questions. Anyway:
I have a program that saves its state into a file and then loads it later. Just some basic stuff, integers, doubles, maybe a string here and there. So far I've been using .txt files, but I want to move onto another format. I know I can save with just about any extension I want (.sav .dat .map etc.) but opening it up in notepad just has the text info as expected, which means the user can fiddle all they want.
What I want to do is take the data I'm saving and convert it to binary or bitcode or whatever it's called so notepad (or any other text editor) will just put out random characters, like so: -‡Wk]s9µî,¯k^û.
I thought about rotating my characters before writing them out but that doesn't seem like it'll jumble it up as much as I want.
As you can probably already tell, I don't really know the correct name for the concept I'm trying to implement here. Sorry if that all seemed a little rambly.
If you're looking for a quick way to obfuscate your saved data, you could consider Base64 encoding. Here's some code that deals with this algo.
Please note that the Base64 encoding is not secure enough for storing sensitive info such as passwords, credit-card numbers and e-mails etc. However, for storing some program settings in an obfuscated manner so that the end-users don't mess with it, this ought to be sufficient.
You could consider writing your settings data in the binary mode (pass mode as b to the fopen function or use ios::binary flag with fstream objects).

C++ - How could I do some operation on bmp file?

I am interesting to do some transformation, like change one color to another, count all used colors, and resize image. I DO NOT want to use any exist library, I would like write myslelf all code.
Summing up: How could I open BMP file and change it?
Start by learning the bitmap file format. It is very easy to understand and implement.
You can get any file format by going to www.wotsit.org and searching for the file type you want. In your case BMP. There are different types of bitmaps so you can figure out which ones you want to implement.
I would start with reading some documentation. Maybe go to Wikipedia for an overview.
You need to read in the binary file, figure out what all the bits mean, do your transformation, and write out a new binary file. For figuring out the format of various binary files, wotsit is the best resource I've found. They have links to 5 specs for BMP format files.

Game Programming: .DAT file?

I've seen a lot of games use something similar to a .DAT file or a specific file type that the game has for itself. I'm just beginning with C++ and DirectX and I was interested in keeping my information in something similar to a .DAT.
My initial conception was that it would hold information on the files you wanted to store within the .DAT file. Something similar to a .RAR file. Unfortunately, my googleing skills did not help me in finding the answers.
Right now I'm simply loading textures and sound files from a folder called Data.
EDIT: While I understand that .DAT is short for data, and I've found that a .DAT file generally contains any assortment of information, I'm still unsure about how to go about doing something as packing images and sound files into any type of file and being able to read them.
I'm not sure about using fstreams to achieve my task, however I will look into streams related to storing data and how to properly read from that data. Meanwhile if anyone has another answer to offer based on this new information, it would be appreciated.
EDIT: Thanks to the answers, I stumbled across a similar question on stackoverflow and felt I'd share it here. Combining resources into a single binary file
I don't think there is really such thing as .dat file format. It's short for "data," and different applications just put in some proprietary stuff in it and call it ".dat." You can read up on fstream classes to do file IO in C++. See Input/Output with files.
What you then do is make up your own file format. For example, first 4 byte is int that indicates the number of blocks in the .dat and for each block, you have 4 byte indicating the length of each block, 4 byte indicating the type of the block, the variable length data itself .. something like that.
DAT obviously stands for data, and there is no real or de facto standard on what that extension actually refers to. Your decisions on the best file formats should be based on technical considerations, not pointless attempts at security through obscurity.
Professional games use a technique where they put all the needed resources (models, textures, sounds, ai, config, etc) zipped/packed into a single file thus making it faster to manage, harder to change (some even make use of a virtual filing system from what's inside the data file). Now, for what's inside the file is different depending on the needs of the game and the data structures that you use.
If you're just starting into gamedev, i recommend you stick with keeping all you assets separate and don't bother too much about packing them into a single file.
Now if you really want to start using a packed format here's a good pointer:
Creating a PAK File Format
Here's a link which claims that .dat is a movie format, 'DAT' being short for Digital Audio Tape.
I'm not sure I believe the link, but I do remember something about a Microsoft supported format called DAT, from long ago, when I used an earlier version of Windows.
It makes more sense as a logical extension for a DATA file of some kind.
.dat, as others have said, is literally just a data file. In reality, the file extension means nothing other than association with a program. For example, I could make a word processor that saves all the documents with the .mp3 file extension. These files wouldn't be playable in any media software, but the software might try. File extensions are used to help programs know what types of files they can and cannot open--however those rules don't have to be followed.
Anyway, you can dump any sort of information to a file. Programmers/software writers will often choose .dat as the extension of that file because it has become the standard to signify 'this file just holds a ton of data' and that the data doesn't necessarily hold any standardized headers, footers, or formatting.
A dat file could really contain anything. It might be as simple as a zip archive with the extension changed, or it could be a completely custom file type. If you're just starting out, you probably don't want to write your own file format, although doing so can be fun and educational. If you want to encapsulate your data files into some kind of container, you should probably go with a zip, paq, or maybe tar.gz.