473,321 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

fstream.read() Not Reading Anything At All.

2
Hi guys.
I'm trying to read the first line of an MP3 file (I edited this mp3 file to contain the text "I'm an MP3" right at the beginning of the file).

This is what I'm trying to do:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     fstream mp3;
  9.     mp3.open("05 Imagine.mp3", ios::binary | ios::in | ios::out);
  10.     /*mp3.seekg(0, ios::end);
  11.     int lof = mp3.tellg();
  12.     cout << "Length of file: " << lof << endl;
  13.     mp3.seekg(0, ios::beg);*/
  14.  
  15.     //char ch;
  16.     //cout << mp3.get(ch) << endl;
  17.  
  18.     char* somebuf;
  19.     while(mp3.read(somebuf, 10)) //Read the first 10 chars which are "I'm an MP3 file".
  20.     {
  21.         //cout << somebuf;
  22.     }
  23.     return 0;
  24. }
For some reason, that is crashing. At some point it didn't crash, but it didn't print anything when I did cout << somebuf. Can someone help me with this?
Dec 17 '11 #1
1 2014
Leonne
2
I wasn't initializing the buffer.
Expand|Select|Wrap|Line Numbers
  1. char* somebuf = new char[11]; //Fixes it.
Dec 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
2
by: dumboo | last post by:
hi there i m using fstream object for reading through and writing to my file, using following code char c; while(!m_aa.eof()) { m_aa.read(&c, sizeof(c)); m_oo.write(&c, sizeof(c));
3
by: poifull | last post by:
Hi All, What is the proper way to read a binary file into a byte? I am using BinaryReader to read from a Stream and call the ReadByte method of the BinaryReader object. The method I'm using...
3
by: Brad | last post by:
I'm working on a web app which will display LARGE tiff image files (e.g files 10-20+ mb). Files are hidden from users direct access. For other, smaller image files I have used FileStream to read...
29
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
29
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
1
by: Neil Hughes | last post by:
Hi All, Sorry if this is a question covered before but I'm having a torid time trying to get an fstream to behave. Essentially when I embed the code snipet below into a program, and give it a file...
10
by: CDFTim | last post by:
O.K. that was a long Title... Can you help / show me how I would......... I am going to long windedly try to paint this picture. Backround: I have an html page that has a marquee function in it to...
1
by: aviraldg | last post by:
I'm having a problem with read , my code is somewhat like: char chipMemory ; // ~35XX fstream ifile; ifile.open(argv,ios::in|ios::binary|ios::nocreate|ios::ate); int fileLength=ifile.tellg();...
1
by: stephen beharry | last post by:
Im using Visual C++ 2008 edition complier...i'm having a bit of a problem reading and storing data from a user specified file. It compiles but when executed program ends without reading anything into...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.