当前位置: 首页>>代码示例>>C++>>正文


C++ ofstream::put方法代码示例

本文整理汇总了C++中std::ofstream::put方法的典型用法代码示例。如果您正苦于以下问题:C++ ofstream::put方法的具体用法?C++ ofstream::put怎么用?C++ ofstream::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ofstream的用法示例。


在下文中一共展示了ofstream::put方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: archiving

void Hoffman::archiving(std::ifstream &f,std::ofstream &g,std::map<char,int> &counting)
{
	int sz = counting.size();
	g.write(reinterpret_cast<char *>(&sz), sizeof(sz));
	for (std::map<char, int>::iterator i = counting.begin(); i != counting.end(); ++i)
	{
		char fr = i->first;
		int sc = i->second;
		g.write(reinterpret_cast<char *>(&fr), sizeof(char));
		g.write(reinterpret_cast<char *>(&sc), sizeof(int));
	}
	while((c1=f.get()) != EOF)//считали из файла букву,чтобы входили и пробелы
	{
		std::vector<bool>x=catalogue[c1];//использу¤ ключ мы выводим код
		for(int n=0;n<x.size();n++)
		{
			if(DEBUG) std::cout <<x[n];//выведем на экран
			///////выведем в файл///////
			buf=buf | x[n]<<(7-count);//изначально buf 00000000
			count++;
			if(count==8){count=0;g.put(buf);buf=0;}
		}
		std::cout<<" ";
	}
	if( count > 0) g.put(buf);
	std::cout<<std::endl;
}
开发者ID:lenarano,项目名称:TRiTPO,代码行数:27,代码来源:Hoffman.cpp

示例2: replaceTabs

/* This function includes an optional tab size selecter, but defaults at 4 spaces */
void replaceTabs(std::ifstream &inFile, std::ofstream &outFile, int numTab = 4) {
    char ch;
    int spaceCounter = 0;
    int sizeToTab = 0;
    while (inFile.get(ch)) {
        if (ch == '\n') spaceCounter = -1;
        if (spaceCounter < 0) {
            sizeToTab = numTab;
        } else {
            sizeToTab = numTab - (spaceCounter % numTab);
        }
        if (ch == '\t') {
            for (int i = 0; i < sizeToTab; i++) {
                outFile.put(' ');
                std::cout << ' ';
            }
            spaceCounter += sizeToTab;
        } else {
            outFile.put(ch);
            std::cout << ch;
            spaceCounter++;
        }
    }
    
    
    
}
开发者ID:NikkiJain09,项目名称:programming-abstractions,代码行数:28,代码来源:4_10.cpp

示例3: escape

void XMLWriter::escape(std::ofstream& iOS, var iVar)
{
    const char* str = iVar.str();
    for (int i=0; i<iVar.size(); i++)
        switch (str[i])
        {
        case '&':
            iOS << "&amp;";
            break;
        case '<':
            iOS << "&lt;";
            break;
        case '>':
            iOS << "&gt;";
            break;
        case '\'':
            iOS << "&apos;";
            break;
        case '"':
            iOS << "&quot;";
            break;
        default:
            iOS.put(str[i]);
            break;
        }
}
开发者ID:pgarner,项目名称:libube,代码行数:26,代码来源:xmlfile.cpp

示例4: WriteString

// flushing strings
static void WriteString ( std::ofstream &s, std::string &val)
{
  s << (uint32) val.size() << " ";
  for( uint32 i=0; i< val.size(); i++)
  {
    s.put(val[i]);
  }
  s << " ";
}
开发者ID:JanKolomaznik,项目名称:MedV4D,代码行数:10,代码来源:LocalService.cpp

示例5: main

int main(int argc, char* argv[]){
    if (argc != 3) {
	    std::cout << argv[0] << " called with incorrect arguments. "<< std::endl;
	    std::cout << "Usage:" << std::endl;
	    std::cout << argv[0] << " infile outfile" << std::endl;
    	exit(-1);
    }

    infile.open(argv[1], ios::binary); // Open input file
    outfile.open(argv[2], ios::binary); // Open output file

	BitInputStream* input = new BitInputStream(infile);

    if(infile.is_open()) {

        // Read the number of unique bytes
        unsigned int tlength = input -> readInt(); 
        // Read the length of the original text
        int textbytes = input -> readInt();

        // Read the frequencies of each byte from the header
	    unsigned int i = 0; // Start past the two nums, at the actual header
        while( i < tlength) {
            int d = input -> readInt();
            int s = input -> readByte();
            
            freq[s] = d;
            i++;
       } 
        
       // Build the tree from the frequencies
        HCTree* myTree = new HCTree();
        myTree->build(freq);

        //Decode individual bytes
        int y = 0;
        while (infile.good() && y < textbytes) {
            int decoded = myTree -> decode(*input);
            outfile.put((unsigned char)decoded);
            y++;
        }
        outfile.flush();
    }
    else {
        std::cout << argv[0] << " called with incorrect arguments. "<< std::endl;
	    std::cout << "Usage:" << std::endl;
	    std::cout << argv[0] << " infile outfile" << std::endl;
    	exit(-1);
    }

    infile.close();
    outfile.close();
}
开发者ID:iphone5sbetter,项目名称:CS100Assignments,代码行数:53,代码来源:uncompress.cpp

示例6: unload_rle_data

// TODO: it is not necessary to break a raw chunk for two equal pixels (for the matter of the resulting size)
bool TGAImage::unload_rle_data(std::ofstream& out)
{
	const unsigned char max_chunk_length = 128;
	unsigned long npixels = width * height;
	unsigned long curpix = 0;
	while(curpix < npixels)
	{
		unsigned long chunkstart = curpix * bytespp;
		unsigned long curbyte = curpix * bytespp;
		unsigned char run_length = 1;
		bool raw = true;
		while(curpix + run_length < npixels && run_length < max_chunk_length)
		{
			bool succ_eq = true;
			for(int t = 0; succ_eq && t < bytespp; t++)
			{
				succ_eq = (data[curbyte + t] == data[curbyte + t + bytespp]);
			}
			curbyte += bytespp;
			if(1 == run_length)
			{
				raw = !succ_eq;
			}
			if(raw && succ_eq)
			{
				run_length--;
				break;
			}
			if(!raw && !succ_eq)
			{
				break;
			}
			run_length++;
		}
		curpix += run_length;
		out.put(raw ? run_length - 1 : run_length + 127);
		if(!out.good())
		{
			std::cerr << "can't dump the tga file\n";
			return false;
		}
		out.write((char*)(data + chunkstart), (raw ? run_length* bytespp : bytespp));
		if(!out.good())
		{
			std::cerr << "can't dump the tga file\n";
			return false;
		}
	}
	return true;
}
开发者ID:woland,项目名称:tiny,代码行数:51,代码来源:tgaimage.cpp

示例7: doFilter

void CipherEncrypt::doFilter(std::ifstream &in, std::ofstream &out)
{
	char ch;
	in.get(ch);

	wordCount = 0;
	lineCount = 0;

	while(in.good())
	{
		if (ch == ' ') // ignore spaces and white space please.
			in.get(ch); 

		else
		{
			wordCount++;
			if(wordCount % 6 == 0)
			{
				out.put(' ');
			}

			else
			{
				if(ch == 10) // let's get a new line and start over.
				{
					wordCount = 0;
				}

				ch = transform(ch);
				out.put(ch);
				in.get(ch);

			}
		}
	}
}
开发者ID:amcalhoun84,项目名称:Comp-Sci-162---CPP,代码行数:36,代码来源:cipherFilter.cpp

示例8: write_packed

   void write_packed(unsigned char *data, int size, std::ofstream &f)
   {
      unsigned char c = 0;

      int bitshift = 7;
      for (int pos = 0; pos < size; pos++) {
         c = c | (data[pos] << bitshift);
         bitshift--;
         if ((bitshift == -1) || (pos == size-1)) {
            f.put(c);
            bitshift = 7;
            c = 0;
         }
      }
   }
开发者ID:HWiese1980,项目名称:insight3d,代码行数:15,代码来源:image_io_pnm.cpp

示例9: banishCharacters

void banishCharacters(std::ifstream &inFile, std::ofstream &outFile, std::string toBanish) {
    char ch;
    while (inFile.get(ch)) {
        bool toPut = true;
        for (int i = 0; i < toBanish.length(); i++) {
            if (toBanish.at(i) == ch) {
                toPut = false;
            }
        }
        if (toPut) {
            std::cout.put(ch);
            outFile.put(ch);
        }
        
        
    }
}
开发者ID:NikkiJain09,项目名称:programming-abstractions,代码行数:17,代码来源:4_09.cpp

示例10: saveByte

void Entity::saveByte(std::ofstream& file, char c)
{
	file.put(c);
}
开发者ID:hasyimibhar,项目名称:gag,代码行数:4,代码来源:Entity.cpp

示例11: write_padding

void write_padding(std::ofstream& out, int len)
{
    for (int z = 0; z < len; ++z)
        out.put(pad_char);
}
开发者ID:coxlab,项目名称:boost_patched_for_objcplusplus,代码行数:5,代码来源:restrict_test.cpp

示例12: writeToLog

void writeToLog(std::ofstream& file, std::string str)
{
	file.write(str.c_str(), str.length());
	file.put(' ');
}
开发者ID:ocirne23,项目名称:GLEngine,代码行数:5,代码来源:main.cpp

示例13: write

		bool write(const uint8_t v) { m_fp.put(v); return true; }
开发者ID:DimitrisVlachos,项目名称:lib_bitstreams,代码行数:1,代码来源:file_stream.hpp


注:本文中的std::ofstream::put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。