Help Please

This is a discussion on Help Please within the C++ Programming forums, part of the General Programming Boards category; i need help with this program , all it does is stream one file to an output file but it ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    7

    Help Please

    i need help with this program , all it does is stream one file to an output file but it doesnt sound right when it is finish. can someone review this code and help me.
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main()
    {
        int s=0;
        char buffer[10240];
        char name[1024];
       ofstream out ("out.mp3", ios::trunc);
      out.close();
      out.open("out.mp3", ios::app);
       ifstream in ("Bad_...........mp3");
       in.seekg(s, ios::beg);
       in >> buffer;
       out<< buffer;
       out<<" ";
       s = s+strlen(buffer)+1;
       out.close();
       while (s != 0)
       {
              ofstream out ("out.mp3", ios::app);
       ifstream in ("Bad_...........mp3");
       in.seekg(s, ios::beg);
      in >> buffer;
      if (buffer != NULL and buffer != "");
      {
       out<< buffer;
       out<<" ";
       s = s+strlen(buffer)+1;
       out.close();
    }
             if (buffer == NULL)
             {
       out<< buffer;
       out<<"/n";
       s = s+strlen(buffer)+1;
       out.close();
    }
            if (buffer == "")
             {
       out<< buffer;
       out<< " ";
       s = s+strlen(buffer)+1;
       out.close();
    }
           if (buffer == " ")
             {
       out<< buffer;
       out<< " ";
       s = s+strlen(buffer)+1;
       out.close();
    }
    
    }         
      
    }

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    maybe you should open it as a binary file.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    7
    i tryed that already

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    what exactly are you trying to do? if you're just trying to copy a file from one spot to another, try this:
    Code:
    #include<fstream>
    
    int main()
    {
    	char ch;
    	std::fstream in("test.in",std::ios::binary|std::ios::in);
    	std::fstream out("test.out",std::ios::binary|std::ios::out|std::ios::trunc);
    	while(!in.eof())
    	{
    		in.read(reinterpret_cast<char*>(&ch),sizeof(ch));
    		out.write(reinterpret_cast<char*>(&ch),sizeof(ch));
    	}
    	in.close();
    	out.close();
    	return 0;
    }
    this block makes me think you need more practice with file I/O:
    Code:
       ofstream out ("out.mp3", ios::trunc);
      out.close();
      out.open("out.mp3", ios::app);
    that and the fact that you're using binary methods on a non-binary stream. this is a great reference.
    Last edited by major_small; 07-02-2005 at 01:17 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Easiest way (and fairly quick too) would perhaps be:

    Code:
    #include <fstream>
    
    int main()
    {
        ifstream in("in.mp3",ios::in|ios::binary);
        ofstream out("out.mp3",ios::out|ios::binary);
    
        if( in.is_open() && out.is_open() )
            out << in.rdbuf();
    
        return 0;
    }
    I used to be an adventurer like you... then I took an arrow to the knee.

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    7
    thanks guys and you are right i need more practice with file i/o

  7. #7
    Registered User
    Join Date
    Feb 2005
    Posts
    7
    to think of it if you know some good file i/o website post them thanks

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21