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


C++ write_to_file函数代码示例

本文整理汇总了C++中write_to_file函数的典型用法代码示例。如果您正苦于以下问题:C++ write_to_file函数的具体用法?C++ write_to_file怎么用?C++ write_to_file使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: write_to_file

void input_manager::save()
{
    write_to_file( FILENAMES["user_keybindings"], [&]( std::ostream & data_file ) {
        JsonOut jsout( data_file, true );

        jsout.start_array();
        for( t_action_contexts::const_iterator a = action_contexts.begin(); a != action_contexts.end();
             ++a ) {
            const t_actions &actions = a->second;
            for( const auto &action : actions ) {
                const t_input_event_list &events = action.second.input_events;
                jsout.start_object();

                jsout.member( "id", action.first );
                jsout.member( "category", a->first );
                bool is_user_created = action.second.is_user_created;
                if( is_user_created ) {
                    jsout.member( "is_user_created", is_user_created );
                }

                jsout.member( "bindings" );
                jsout.start_array();
                for( const auto &event : events ) {
                    jsout.start_object();
                    switch( event.type ) {
                        case CATA_INPUT_KEYBOARD:
                            jsout.member( "input_method", "keyboard" );
                            break;
                        case CATA_INPUT_GAMEPAD:
                            jsout.member( "input_method", "gamepad" );
                            break;
                        case CATA_INPUT_MOUSE:
                            jsout.member( "input_method", "mouse" );
                            break;
                        default:
                            throw std::runtime_error( "unknown input_event_t" );
                    }
                    jsout.member( "key" );
                    jsout.start_array();
                    for( size_t i = 0; i < event.sequence.size(); i++ ) {
                        jsout.write( get_keyname( event.sequence[i], event.type, true ) );
                    }
                    jsout.end_array();
                    jsout.end_object();
                }
                jsout.end_array();

                jsout.end_object();
            }
        }
        jsout.end_array();
    }, _( "key bindings configuration" ) );
}
开发者ID:jc6036,项目名称:Cataclysm-DDA,代码行数:53,代码来源:input.cpp

示例2: main

int main()
{
  int fd = 0;
  if (  -1 == (fd = open("test.log",O_APPEND | O_CREAT | O_RDWR ,0777)) )
    {
      perror("open file failed.");
    }

  char * str = "teststring\n";
  write_to_file(str,fd);
  return 0;
}
开发者ID:huchangqiqi,项目名称:learngit,代码行数:12,代码来源:test.c

示例3: main

int main(int argc, char *argv[])
{
	int ret;
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char *mygroup_p, *script_pid_p, *test_num_p, *chunk_size_p;
	char *num_chunks_p;
	struct sigaction newaction1, newaction2, oldaction1, oldaction2;

	/* Capture variables from the script environment */
	test_num_p = getenv("TEST_NUM");
	mygroup_p = getenv("MYGROUP");
	script_pid_p = getenv("SCRIPT_PID");
	chunk_size_p = getenv("CHUNK_SIZE");
	num_chunks_p	= getenv("NUM_CHUNKS");

	if (test_num_p != NULL && mygroup_p != NULL && script_pid_p != NULL &&
	    chunk_size_p != NULL && num_chunks_p != NULL) {
		scriptpid       = atoi(script_pid_p);
		test_num        = atoi(test_num_p);
		chunk_size	= atoi(chunk_size_p);
		num_of_chunks	= atoi(num_chunks_p);
		sprintf(mygroup,"%s", mygroup_p);
	} else {
		tst_brkm(TBROK, cleanup,
		    "invalid parameters recieved from script\n");
	}

	/* XXX (garrcoop): this section really needs error handling. */

	/* Signal handling for SIGUSR1 recieved from script */
	sigemptyset(&newaction1.sa_mask);
	newaction1.sa_handler = signal_handler_sigusr1;
	newaction1.sa_flags=0;
	sigaction(SIGUSR1, &newaction1, &oldaction1);

	/* Signal handling for SIGUSR2 recieved from script */
	sigemptyset(&newaction2.sa_mask);
	newaction2.sa_handler = signal_handler_sigusr2;
	newaction2.sa_flags = 0;
	sigaction(SIGUSR2, &newaction2, &oldaction2);


	sprintf(mytaskfile, "%s", mygroup);
	strcat (mytaskfile,"/tasks");
	/* Assign the task to it's group */
	write_to_file (mytaskfile, "a", getpid());    /* Assign the task to it's group*/

	ret = allocate_memory();	/*should i check ret?*/

	cleanup();

	tst_exit();
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:53,代码来源:memctl_test01.c

示例4: update_t_low

static void update_t_low(u32 t_low)
{
    char buf[SIZE];
#ifdef DEBUG
    LOGD("update_t_low (%ld)\n", t_low);
#endif
    sprintf(buf, "%ld\n", convert_hotspot_temp_to_omap_sensor_temp(OMAP_CPU, t_low));
    write_to_file(
        config_file.omaptemp_file_paths[OMAP_CPU_THRESHOLD_LOW_PATH],
        buf);
    current_t_low = t_low;
}
开发者ID:CM7lu3000,项目名称:android_hardware_ti_omap3,代码行数:12,代码来源:cpu_thermal_governor.c

示例5: update_omap_rate

/*
 * The goal of this function is to update the setting of monitoring
 * rate only if this is required to avoid useless SYSFS accesses.
 */
static void update_omap_rate(u32 rate)
{
    char buf[SIZE];

    if (update_rate != rate) {
        sprintf(buf, "%ld\n", rate);
        write_to_file(
            config_file.omaptemp_file_paths[OMAP_CPU_UPDATE_RATE_PATH],
            buf);
        update_rate = rate;
    }
}
开发者ID:CM7lu3000,项目名称:android_hardware_ti_omap3,代码行数:16,代码来源:cpu_thermal_governor.c

示例6: set_cpu_params

int set_cpu_params(char *governor, char *min_freq, char *max_freq)
{
    if (write_to_file(SYS_CGOV_C0, governor) != 0)
        return -1;
    if (write_to_file(SYS_CMAX_C0, max_freq) != 0)
        return -1;
    if (write_to_file(SYS_CMIN_C0, min_freq) != 0)
        return -1;

    write_to_file(SYS_CGOV_C1, governor);
    write_to_file(SYS_CMAX_C1, max_freq);
    write_to_file(SYS_CMIN_C1, min_freq);

    char buf[255];
    buf[0] = 0;
    strcat(buf, "Setting CPU Params: Governor=");
    my_trim(governor);
    strcat(buf, governor);
    strcat(buf, " min_freq=");
    my_trim(min_freq);
    strcat(buf, min_freq);
    strcat(buf, " max_freq=");
    my_trim(max_freq);
    strcat(buf, max_freq);
    __android_log_write(ANDROID_LOG_INFO, APPNAME, buf);
    return 0;
}
开发者ID:bmourit,项目名称:oc_daemon,代码行数:27,代码来源:virtuous_oc.c

示例7: write_to_file

bool mod_manager::set_default_mods(const t_mod_list &mods)
{
    default_mods = mods;
    return write_to_file( FILENAMES["mods-user-default"], [&]( std::ostream &fout ) {
        JsonOut json( fout, true ); // pretty-print
        json.start_object();
        json.member("type", "MOD_INFO");
        json.member("ident", "user:default");
        json.member("dependencies");
        json.write(mods);
        json.end_object();
    }, _( "list of default mods" ) );
}
开发者ID:EpicOrange,项目名称:Cataclysm-DDA,代码行数:13,代码来源:mod_manager.cpp

示例8: file_cache_destroy

void file_cache_destroy(file_cache *cache){
   while(cache){
	   if(cache->pin && cache->dirty){ // Search through each cache to check for dirty buffer.
		   write_to_file(cache);
		   #ifdef DEBUG
				printf("\n Successfully written to file %s \n",cache->filename);
				fflush(stdout);
           #endif  /* DEBUG */
	   }
	   strcpy(cache->buf,""); /*make the cache buffer empty for the nondirty node */
	   cache = cache->next;
   }	
}	
开发者ID:koshyg,项目名称:file_cache_without_threads,代码行数:13,代码来源:file_cache.c

示例9: fhopen_file

static void
fhopen_file(int num, struct fhb_handle *handle)
{
    int fd;

    fd = fhb_fhopen(handle, O_RDWR);
    if (fd < 0)
	err(1, "open");

    if (write_file)
	write_to_file(fd, write_file);
    close(fd);
}
开发者ID:maxendpoint,项目名称:openafs_cvs,代码行数:13,代码来源:fhbench.c

示例10: cmd_close_flow

/**
 * closes a flow described by fd
 * if send_reply is non-zero, a response is sent to client's mapi stub,
 * (send_reply=0 is used for local clean-ups)
 */
static void cmd_close_flow(int fd, int pid, int sock, int send_reply) {
	struct flow *f;
	struct client *cl;
	struct mapiipcbuf buf;
	long file_size;

	f=(struct flow*)flist_get(flowlist, fd);

	if (f) {
		/* to avoid reading memory after it's freed */
		int tmpfd = f->fd;
		/* prevent closing flows of other processes */
		if (pid != f->id) {
			DEBUG_CMD(Debug_Message(
					"Proc %d tried to close flow %d, which belongs to proc %d",
					pid, f->fd, f->id));
			report_error(MAPI_INVALID_FLOW, pid, sock);
			return;
		}

		cleanup_flow(f);

		while(__sync_lock_test_and_set(&clientlist_lock,1));
		cl = flist_get(clientlist, pid);
		f = (struct flow *) flist_remove(cl->flowlist, fd);
		cl->numflows--;
		clientlist_lock = 0;

		//send an ACK that flow closed
		if (send_reply) {

			buf.mtype = pid;
			buf.cmd = CLOSE_FLOW_ACK;
			buf.fd = tmpfd;
			mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);

			if (log_to_file) {
				file_size = acquire_write_lock(log_fd_info);
				write_to_file(log_fd_info, "MAPID: flow %d was closed at ",
						buf.fd);
				write_date(log_fd_info);
				write_newline(log_fd_info, "\n");
				release_write_lock(log_fd_info, file_size);
			}
			if (log_to_syslog)
				log_message("flow %d was closed", buf.fd);
		}
	} else {
		report_error(MAPI_INVALID_FLOW, pid, sock);
	}
}
开发者ID:helios66,项目名称:loss_estimate,代码行数:56,代码来源:mapid.c

示例11: enable_zfcp_device

/*
 * Enable the scsi disk for dumping
 * Return:    0 - ok
 *         != 0 - error
 */
static int enable_zfcp_device(void)
{
	char command[1024], file[1024];
	struct stat s;

	/* device */
	if (read_file(IPL_DEVNO, g.dump_devno, sizeof(g.dump_devno)))
		return -1;
	sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/online", g.dump_devno);
	if (write_to_file(file, "1\n"))
		return -1;

	/* wwpn */
	if (read_file(IPL_WWPN, g.dump_wwpn, sizeof(g.dump_wwpn)))
		return -1;
	sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/port_add", g.dump_devno);
	/* The port_add attribute has been removed in recent kernels */
	if (stat(file, &s) == 0) {
		sprintf(command, "%s\n", g.dump_wwpn);
		if (write_to_file(file, command))
			return -1;
	}

	/* lun */
	if (read_file(IPL_LUN, g.dump_lun, sizeof(g.dump_lun)))
		return -1;
	sprintf(file, "/sys/bus/ccw/drivers/zfcp/%s/%s/unit_add", g.dump_devno,
		g.dump_wwpn);
	sprintf(command, "%s\n", g.dump_lun);
	if (write_to_file(file, command))
		return -1;

	/* bootprog */
	read_file("/sys/firmware/ipl/bootprog", g.dump_bootprog,
		sizeof(g.dump_bootprog));

	return 0;
}
开发者ID:transformersprimeabcxyz,项目名称:s390-tools-qemu,代码行数:43,代码来源:zfcpdump.c

示例12: TEST_F

	TEST_F(PNGReaderTest, ReadFile)
	{
		static constexpr unsigned int VALID_WIDTH = 2;
		static constexpr unsigned int VALID_HEIGHT = 2;
		static constexpr Color VALID_COLORS[VALID_HEIGHT][VALID_WIDTH] = {{Color::red(), Color::yellow()},
		                                                                  {Color::green(), Color::blue()}};
		ScopedTempDir temp_dir;

		const std::string valid_path = temp_dir.path() / "valid.png";
		write_to_file(valid_path, png_data());
		Image image = PNGReader().read_file(valid_path);

		ASSERT_EQ(VALID_WIDTH, image.width());
		ASSERT_EQ(VALID_HEIGHT, image.height());

		for (unsigned int y = 0; y < VALID_HEIGHT; y++)
		{
			for (unsigned int x = 0; x < VALID_WIDTH; x++)
			{
				Color valid_color = VALID_COLORS[y][x];
				Color color = image.read_pixel(x, y);

				EXPECT_NEAR(valid_color.r(), color.r(), 1e-100);
				EXPECT_NEAR(valid_color.g(), color.g(), 1e-100);
				EXPECT_NEAR(valid_color.b(), color.b(), 1e-100);
			}
		}

		const std::string corrupt_path = temp_dir.path() / "corrupt.png";
		write_to_file(corrupt_path, corrupt_png_data());
		EXPECT_THROW(PNGReader().read_file(corrupt_path), PNGReader::Exception);

		const std::string short_path = temp_dir.path() / "short.png";
		write_to_file(short_path, short_png_data());
		EXPECT_THROW(PNGReader().read_file(short_path), PNGReader::Exception);

		EXPECT_THROW(PNGReader().read_file(temp_dir.path() / "does_not_exist.png"), PNGReader::Exception);
	}
开发者ID:martin-ejdestig,项目名称:rayni-staging,代码行数:38,代码来源:png_reader.cpp

示例13: write_to_file

void ProtobufFileOutputService::execute() {
  bool wrote = false;
  for (auto& sensor : sensors_) {
    for (int i = 0;
        sensor->protobuf_file_fifo_is_empty() == false
            && i < MAX_READINGS_PER_STEP; i++) {
      wrote = true;
      write_to_file(sensor);
    }
  }
  if (!wrote) {
    std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
  }
}
开发者ID:droberg,项目名称:yamsLog,代码行数:14,代码来源:ProtobufFileOutputService.cpp

示例14: main

int main(void)
{
    I16 card, err;

    setbuf( stdout, NULL );
    printf("This program inputs %ld data from CH-0 to CH-%d of PCI-9812 in %d Hz, and\nstore data to file '%s'.\nPlease press any key to start the operation.\n", read_count, channel, (int)sample_rate, file_name);

    getch();
    if ((card=Register_Card (PCI_9812, 0)) <0 ) {
        printf("Register_Card error=%d\n", card);
        exit(1);
    }
    err = AI_9812_Config(card, P9812_TRGMOD_SOFT, P9812_TRGSRC_CH0, P9812_TRGSLP_POS, P9812_AD2_GT_PCI|P9812_CLKSRC_INT, 0x80, 0);
    if (err!=0) {
       printf("AI_9812_Config error=%d", err);
       exit(1);
    }
    err = AI_AsyncDblBufferMode(card, 0);
    if (err!=0) {
       printf("AI_DblBufferMode error=%d", err);
       exit(1);
    }

    mem_size=read_count * 2;
    ai_buf = (I16*)malloc(mem_size);

    err = AI_ContScanChannels(card, channel, range, ai_buf, read_count, sample_rate, SYNCH_OP);
    if (err!=0) {
       printf("AI_ContReadChannel error=%d", err);
       free( ai_buf );
       Release_Card(card);
       exit(1);
    }

    printf(" %ld data trnasfered !\n", read_count );

    Release_Card(card);

	  if( write_to_file( (U16*)ai_buf, channel+1 ) )
        printf("\n\nThe input data is already stored in file '%s'.\n", file_name);

	  //    show_channel_data( (U16*)ai_buf, channel+1 );
    plot_channel_data();
    free( ai_buf );

    printf("\nPress ENTER to exit the program. "); 
    //getch(); 
    //putchar('\n');
    return 0;
}
开发者ID:abrahamneben,项目名称:orbcomm_beam_mapping,代码行数:50,代码来源:oldgetsatdat.c

示例15: signal_handler

void signal_handler(int sig_no)
{
    BOOLEAN HalfReady;

    HalfReady=0;
    DI_AsyncMultiBufferNextReady(card, &HalfReady, &viewidx[j%10000]);
    switch(viewidx[j%10000]) {
        case 0:
            write_to_file( in_buf );
            break;
        case 1:
            write_to_file( in_buf2 );
            break;
    }
    DI_AsyncDblBufferTransfer(card, NULL);  //notify the buffer have handled
    DI_AsyncDblBufferOverrun(card, 0, &sts);
    if(sts==1) {
        t++;
        DI_AsyncDblBufferOverrun(card, 1, &sts);
    }
    printf("\roverrun:%d cb:%d", t, j);
    j++;
}
开发者ID:ellysh,项目名称:pci-dask,代码行数:23,代码来源:7300mdi.c


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