Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 读取文件处理c++;_C++ - Fatal编程技术网

C++ 读取文件处理c++;

C++ 读取文件处理c++;,c++,C++,我正在做一棵哈夫曼树,我已经完成了我的工作。但是当我读取字符时出现了一个问题,它在第一部分中读取的是零而不是空格“” 这是代码。文件处理期间,解码功能中出现错误 void huffmantree<h>::decode(){ CString *st; hscll<h> * temp=new hscll<h> (); int h; ifstream myfile; myfile.open ("z://aaaaaaaaaaaaaaaaaaaaaa

我正在做一棵哈夫曼树,我已经完成了我的工作。但是当我读取字符时出现了一个问题,它在第一部分中读取的是零而不是空格“”

这是代码。文件处理期间,
解码
功能中出现错误

void huffmantree<h>::decode(){
    CString *st;
hscll<h> * temp=new hscll<h> ();
int h;
    ifstream myfile;
  myfile.open ("z://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae.txt");
  myfile >>h;
  cout<<h;

  for(int i=0;i<h;i++)
  {char  temp9[100];
  char l;

  myfile >>l; 
  temp->insert(l);
     // myfile >> l ;

      myfile >> temp9;
      temp->atindex(i)->symboc.symbol=l;
      temp->atindex(i)->code->setString(temp9);
      //myfile >> '\n';
  }
  _getch();

    //CString u;
    //char k;
    //int p=0;
    //for(int i=0;i<st->m_length;i++)
    //{
    //  for(int j=0;j<8;j++)
    //  {
    //      
    //      char a;
    //      a=st->charAt(i);
    //      int temp=1;
    //      if(j==0)
    //          temp=1;
    //      if(a!='0')
    //      {
    //          for(int y=0;y<j;y++)
    //              {
    //                      temp*=2;
    //              }
    //          p+=temp;
    //      }
    //      else 
    //      {
    //      p+=0;
    //      
    //      }

    //      i++;
    //      cout<<a;
    //  }
    //  k=p;
    //  char t=7;
    //  //cout<<"      "<<t<<"    "<<p<<endl;
    //  myfile << k;
    //  p=0;
    //  u.addcharbychar(k);
    //}
    ////cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<u.getString();
    ////cout<<endl<<endl<<endl<<"the length is =="<<u.m_length<<endl;
  myfile.close();
}
void huffmantree::decode(){
CString*st;
hscll*temp=新的hscll();
int-h;
ifstreammyfile;
myfile.open(“z://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
myfile>>h;
库廷塞特(l);
//myfile>>l;
myfile>>temp9;
温度->指数(i)->符号=l;
temp->atindex(i)->code->setString(temp9);
//myfile>>'\n';
}
_getch();
//CSTU;
//chark;
//int p=0;
//对于(int i=0;im_长度;i++)
//{
//对于(int j=0;jcharAt(i);
//内部温度=1;
//如果(j==0)
//温度=1;
//如果(a!=“0”)
//      {

//对于(int y=0;y,如果使用
>
进行输入,将跳过前导空格。如果正在读取二进制数据,则需要以二进制模式打开文件(
myfile.open(name,std::ios::in | std::ios::binary
),并使用非格式化输入函数,如
istream::get()
)。(在编写时,还需要编写二进制文件。)

你可以使用你的意思是
std::noskipws
来跳过空格;
std::ws
显式跳过空格。你可以,但使用为这种工作设计的函数更自然。是的,
std::noskipws
。不知何故,我认为这是一个二进制切换…我的错误。