本文整理汇总了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);
}
示例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;
//.........这里部分代码省略.........
示例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)