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


C++ FILE::close方法代码示例

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


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

示例1: main

int main(int argc, char** argv)
{
  double d;
  int n = 1;
  if( argc!=2) {
    printf( "usage: program <number of numbers to read>\n");
    return -1;
  }

#ifdef STDIO
    FILE *f;
    f = fopen( "numbers.txt", "r");
    if ( !f) {
      printf( "Cannot open file\n");
      return -1;
}
    VALUES = atoi( argv[1]);

    for ( ; VALUES; --VALUES) {
      fscanf( f,"%lf", &d);
      printf( "%10.5f", d);
#else
      ifstream f( "numbers.txt", ios_base::in);
      if( !f.is_open()) {
          cout << "Cannot open file\n";
          return -1;
      }
    VALUES = atoi( argv[1]);

    for ( ; VALUES; --VALUES) {
      f >> d;
      cout  << std::setw(10)
      << std::setprecision(5)
      << std::setiosflags( ios::showpoint)
      << std::setiosflags( ios::fixed)
      << d;
#endif

    if (n % 5 == 0) {
#ifdef STDIO
      printf("\n");
#else
      cout << '\n';
#endif
    }
  }

#ifdef STDIO
    fclose( f);
#else
    f.close();
#endif

return (EXIT_SUCCESS);
}
开发者ID:gaizoule,项目名称:examples,代码行数:55,代码来源:main.cpp

示例2: if

void *connection_handler(void *socket_desc) {

    FILE *file;

    int sock = *(int*) socket_desc;
    int read_size;
    char *message, client_message[8192];
    OggStream* stream = 0;
    StreamMap streams;

    // start opus 
    int error;
    OpusDecoder *dec;
    dec = opus_decoder_create(16000, 1, &error);
    if (error != OPUS_OK && dec == NULL) {
        puts("ERROR LOADING OPUS");
    }

    // start pocketsphinx 
    ps_decoder_t *ps = ps_start();

    /* // IF RUN VAD AT SERVER
    VadInst* handle = NULL;
    if (WebRtcVad_Create(&handle) < 0) puts("Error creating WebRtcVad_Create");
    if (WebRtcVad_Init(handle) < 0) puts("Error initializing WebRtcVad_Init");
    if (WebRtcVad_set_mode(handle, 3) < 0) puts("Error setting mode WebRtcVad_set_mode");
     */

    char * dtdepois;
    bool ended = true;
    while ((read_size = recv(sock, client_message, 8192, 0)) > 0) {

        char otherString[3];
        strncpy(otherString, client_message, 3);

        if (strcmp(otherString, "#JS") == 0) {
            puts("GRAM RECVD. SWITCH");

            string str1(client_message);


            char *dtgram = current_timestamp();
            std::string grampath = "/var/www/speechrtc/voiceserver/" + std::string(dtgram) + ".jsgf";
            ofstream file;
            file.open(grampath.c_str());
            file << str1;
            file.close();


            jsgf_rule_iter_t *itor;
            jsgf_t * gram = jsgf_parse_file(grampath.c_str(), NULL);
            jsgf_rule_t * rule;

            for (itor = jsgf_rule_iter(gram); itor; itor = jsgf_rule_iter_next(itor)) {
                rule = jsgf_rule_iter_rule(itor);
                if (jsgf_rule_public(rule))
                    break;
            }

            fsg_model_t * m = jsgf_build_fsg(gram, rule, ps_get_logmath(ps), 6.5);
            fsg_set_t* fsgset = ps_get_fsgset(ps);
            fsg_set_add(fsgset,  dtgram , m);
            fsg_set_select(fsgset , dtgram );
            ps_update_fsgset(ps);
            continue;
        }

        if (strcmp(otherString, "STA") == 0) {

            //   int _res = ps_start_utt(ps, "goforward");            
            dtdepois = current_timestamp();
            puts(dtdepois);
            file = fopen(dtdepois, "wb+");
            ended = false;
            continue;
        }

        if (strcmp(otherString, "END") == 0) {
            puts("END RECVD");
            fclose(file);

            FILE *_file = fopen(dtdepois, "rb");
            char const *hyp, *uttid;
            int32 score;
            int rv = ps_decode_raw(ps, _file, dtdepois, -1);
            if (rv < 0) puts("error ps_decode_raw");
            hyp = ps_get_hyp(ps, &score, &uttid);

            if (hyp == NULL) {
                puts("Error hyp()");
                write(sock, "ERR", strlen("ERR"));
            } else {
                printf("Recognized: %s\n", hyp);
                // envia final hypothesis             
                write(sock, hyp, strlen(hyp));
            }

            fclose(_file);
            ended = true;
            continue;
//.........这里部分代码省略.........
开发者ID:MaxMillion,项目名称:speechrtc,代码行数:101,代码来源:newmain.cpp

示例3: get_opt


//.........这里部分代码省略.........
                catch (const CORBA::Exception&)
                  {
                    ACE_ERROR_RETURN ((LM_ERROR,
                                      "%s cannot be resolved, exception reason = "
                                      "Unexpected Exception"
                                      "\n",
                                      argvw[0]),
                                      -1);
                  }

                if (b == 1)
                  ACE_DEBUG ((LM_DEBUG,
                              "catior returned true\n"));
                else
                  ACE_DEBUG ((LM_DEBUG,
                              "catior returned false\n"));
                break;
              }
            case 'f':
              {
                int have_some_input = 0;
                int decode_pass_count = 0;

                //  Read the file into a CORBA::String_var.
                ACE_DEBUG ((LM_DEBUG,
                            "reading the file %s\n",
                            get_opt.opt_arg ()));

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
                ifstream ifstr (ACE_TEXT_ALWAYS_CHAR(get_opt.opt_arg ()));

                if (!ifstr.good ())
                  {
                    ifstr.close ();
                    ACE_ERROR_RETURN ((LM_ERROR,
                                      "%s "
                                      "-f %s "
                                      "\n"
                                      "Invalid IOR file nominated"
                                      "\n",
                                      argvw[0],
                                      get_opt.opt_arg ()),
                                      -1);
                  }

                while (!ifstr.eof())
                  {
                    ACE_CString aString;

                    have_some_input = 0;

                    while (!ifstr.eof ())
                      {
                        char ch = 0;
                        ifstr.get (ch);
                        if (ifstr.eof () || ch == '\n' || ch == '\r')
                          break;
                        aString += ch;
                        ++have_some_input;
                      }
#else
                FILE* ifstr = ACE_OS::fopen (get_opt.opt_arg (), ACE_TEXT ("r"));

                if (!ifstr || ferror (ifstr))
                  {
                    if (ifstr)
开发者ID:asdlei00,项目名称:ACE,代码行数:67,代码来源:catior.cpp


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