Homebrew [Homebrew 3DS] How to read all of the bytes from a file in C++?

Momoro

The Dark One
OP
Member
Joined
Oct 7, 2019
Messages
111
Trophies
0
Age
43
XP
163
Country
United States
Hi!

I have the code already-written in C#, but since I am creating a 3DS Homebrew App, I need it to be written in C++.

Here's my C#:

using (BinaryReader br = new BinaryReader(File.OpenRead("path")))
{
br.BaseStream.Seek(0xAC, SeekOrigin.Begin);
var bytes = br.ReadBytes(4);
string result = Encoding.UTF8.GetString(bytes);
}

Could anyone please re-write (or convert) this code into C++ Code?

Thanks :)
 

Pk11

A catgirl with a DSi
Member
Joined
Jun 26, 2019
Messages
1,022
Trophies
1
Age
21
Location
米国
Website
pk11.us
XP
3,045
Country
United States
Code:
FILE *file = fopen("path", "rb"); // Open the file in Read Binary mode
fseek(file, 0xAC, SEEK_SET);      // Seek to offset 0xAC from the start
char bytes[5];                    // Array to hold 5 bytes (Since you're copying to a string you should use one extra to have a null terminator at the end)
fread(bytes, 1, 4, file);         // Read 4 bytes from file to bytes
std::string result = bytes;       // Copy to a std::string
This should do exactly the same as your C# code if I'm understanding it right
 
General chit-chat
Help Users
  • No one is chatting at the moment.
    KenniesNewName @ KenniesNewName: Pop tarts are better cold