Microsoft MVP성태의 닷넷 이야기
안녕하세요.. 파일 생성 처리 문제로 .... [링크 복사], [링크+제목 복사],
조회: 11431
글쓴 사람
생초보 (huss5210 at hanmail.net)
홈페이지
첨부 파일
 

안녕하세요 기초 수준이 초보라... 이상하게 계속 오류가 나거나
저장이 되더라도.. 파일이 구동이 되지 않아서.. 며칠째 같은 코드만 계속 치는거 같아서..
도무지 이해도 안되어서 이렇게.....

파일을 사이즈씩 vector담아서.. 그 데이터를 .... 저장하고 싶습니다.
ㅜㅜ;;;


-----------------------1

#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <vector>

using namespace std;

 
int main(int argc, char *argv[])
{

   std::ifstream in_file;
   std::ofstream out_file;

   vector<unsigned char *> sendI;
   vector<unsigned char *>::iterator sendIt;

  
   
  in_file.open("aa.mp3" , ios::in|ios::binary |ios::ate);
  out_file.open("bb.mp3", ios::out |ios::binary | ios::trunc);
     

     in_file.seekg(0,ios::end);
     int len = in_file.tellg();
     in_file.seekg(0,ios::beg);
  int check = 1024;
  int wilecout = len/check;
  int noreadcout = 0;
  int v_count =0;


      unsigned char *Orig = new unsigned char[check];


  int i=1;
        while ( i <= wilecout )
        {
    in_file.seekg(noreadcout-1,ios::beg);

    in_file.read((char *)Orig,check);
    sendI.push_back(Orig);

    noreadcout = check*i;
       i++;
        }
        
       v_count = len -noreadcout;

  if(v_count > 0)
     {
       in_file.read((char *)Orig,v_count);
    sendI.push_back(Orig);
     }


  out_file.write((const char*) sendI[i],check);
 
    cout << len << endl;
    cout << sendI.size() << endl;
  
 out_file.flush();
 out_file.close();

 in_file.close();
 
 return 0;
}



-----------------------------------------2
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iterator>
#include <vector>

using namespace std;

 
int main(int argc, char *argv[])
{

   std::ifstream in_file;
   std::ofstream out_file;

   vector<unsigned char *> sendI;
   vector<unsigned char *>::iterator sendIt;

  
   
  in_file.open("aa.mp3" , ios::in|ios::binary |ios::ate);
  out_file.open("bb.mp3", ios::out |ios::binary | ios::trunc);
     

     in_file.seekg(0,ios::end);
     int len = in_file.tellg();
     in_file.seekg(0,ios::beg);
     int check = 1024;
     int wilecout = len/check;
     int noreadcout = 0;
     int v_count =0;
 

        int i=1;
        while (    i <= wilecout )
        {
             unsigned char *Orig = new unsigned char[check];

             in_file.seekg(noreadcout,ios::beg);

             in_file.read((char *)Orig,check);
             sendI.push_back(Orig);
   
              //cout << sendI[1] << endl;

             noreadcout = check*i;
         i++;
        }
        
       v_count = len -noreadcout;

        if(v_count > 0)
     {
             unsigned char *Orig1 = new unsigned char[v_count];
 
 
         in_file.read((char *)Orig1,v_count);
             sendI.push_back(Orig1);
     }

       char *ttt = new char[len*2];

        for(sendIt = sendI.begin(); sendIt != sendI.end(); sendIt++)
     {        
             strcat(ttt,(char *)*sendIt);
     }

      out_file.write((const char*)ttt,len);
 
 
    cout << len << endl;
    cout << sendI.size() << endl;
  
    out_file.flush();
    out_file.close();

    in_file.close();
 
 return 0;
}

계속 그자리를 맵도는 것 같아서요..ㅜㅜ;;
혼자 보다가 보니까 이리저리 답을 구하기가 쉽지 않아서 이렇게 .. 글을 올려봅니다.









[최초 등록일: ]
[최종 수정일: 1/26/2010]


비밀번호

댓글 작성자
 



2010-01-26 06시23분
 이런 건 답을 알려드리는 것은 도움이 되지 않습니다. 사실 저도 이젠 나이가 들어서(!) ^^; C/C++ 코드가 눈에도 잘 안들어오고.

혹시, 도구를 사용하시나요? Visual Studio 같은.
가능하면 Visual Studio를 사용하시고요. 그 도구에서 제공하는 디버깅 기능을 사용하십시오. 정지점(Break Point)를 잡고 라인 단위로 코드를 실행하면서 변수의 값들을 하나 하나 추적하다 보면 자신이 원하지 않는 값으로 빠지는 경우를 잡아낼 수 있을 것입니다. (절대, 처음부터 printf 따위로 디버깅하려고 하지 마세요. ^^ - 물론 도움이 되는 경우가 있지만.)

또한, 디버깅이 잘 되는지 확인하기 위해서, 처음에는 텍스트 파일로 10byte 단위로 복사하는 것을 해보세요. mp3는 바이너리라서 복사가 잘 되고 있는지 테스트로 확인하기가 쉽지 않습니다.
 
kevin25
2010-01-26 09시35분
[생초보 ] 답변 감사드립니다.
[guest]

1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
5885guest4/11/20233292c#으로 드림위버같은 거 만들어볼려는데요 [6]
5884궁금이4/11/20233150부모 클래스에서 예외 발생시 힙 영역에 할당 ? [2]
5883코딩초짜4/9/2023313610c언어 usleep 에 대해서 요 [2]
5882조은현4/7/20233091선생님 안녕하세요! wpf의 성능 개선에 대해서 질문드려요! [1]파일 다운로드1
5881guest4/6/20233273static method - <에러메시지 Extension method must be defined in a non-generic static class> [4]
5880유비4/4/20233114WPF DataGrid CollectionView, IEditableCollectionView 관련 문의 [1]
5879guest4/4/20233329Async method의 에러 표시 [3]
5878guest4/3/20233433C#으로 CMOS 설정 변경가능한지요? [4]
5875guest4/2/20233910성태님 책을 완독 하고 Static [7]
5874민성4/1/20233298안녕하세요 질문 하나만 드릴깨요~ [1]
5873guest3/31/20233570제어판에서 삭제불가 MS Edge ---> 레지스트리 편집기에서도 안보임 [6]파일 다운로드1
58723/31/20233223web config 파일 확인부탁드려요 [6]
58713/31/20233136web config 파일 수정이요 [2]파일 다운로드1
5870guest3/30/20233603.NET Core SDK 삭제 시 주의 사항 [4]파일 다운로드1
5869guest3/30/20233817Dictionary의 Update 그리고 Foreach [7]
5868guest3/29/20233284Speech Recognition과 Form1 그리고 정확도 [4]파일 다운로드1
5866월급쟁이3/28/20233386cmake 크로스 컴파일 관련하여 질문이 있습니다 [1]
5865guest3/28/20233260Github Copilot과 코딩실력 향상? [1]
5864guest3/27/20233689System.NullReferenceException - 개체참조가 개체의 인스턴스... [6]파일 다운로드1
5863guest3/24/20233817이벤트 핸들러 사라짐 현상 - Button [4]
5862guest3/21/20233910세계최초 hts와 싱글스레드 [8]
5861다크파이썬3/21/20234095WPF를 사용하려고 하려고 도서 문의합니다. [2]
5860guest3/21/20233359인텔코어 i5 CPU와 스레드 [4]
5859guest3/21/20233169개발 일지 어떻게 관리하시나요? 이런 프로그램 없나요? [3]
5858김태원3/18/20233307안녕하세요! [5]
5857guest3/17/20233353귀도 반 로썸을 보고 [4]
1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...