本文整理汇总了C++中FILE::open方法的典型用法代码示例。如果您正苦于以下问题:C++ FILE::open方法的具体用法?C++ FILE::open怎么用?C++ FILE::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FILE
的用法示例。
在下文中一共展示了FILE::open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zppError
// ctor: input is filename to open.
// only std::ios::in is supported currently.
// if _makeGlobal == TRUE, then the ZipFile is added to the list
// of global zip files.
zppZipArchive::zppZipArchive(const std::string &_fn, std::ios::openmode _mode, bool _makeGlobal)
{
ourFile = false;
zipName = _fn;
canonizePath(zipName);
#ifdef ZPP_INCLUDE_CRYPT
passwd = NULL;
#endif
if (_mode & std::ios_base::in) {
// make sure "binary" mode is selected.
_mode |= std::ios_base::binary;
#ifdef ZPP_USE_STDIO
FILE *infile = fopen(zipName.c_str(),"rb");
current_pos_v=0;
#else
std::ifstream *infile = new std::ifstream();
infile->open(zipName.c_str(),_mode);
#endif
ourFile = true;
#ifdef ZPP_USE_STDIO
if (!infile)
throw zppError("can't open zip file");
#else
if (infile->fail())
throw zppError("can't open zip file");
#endif
str = infile;
} else {
throw ("zppZipArchive:: only std::ios::in currently supported.");
}
priority = defaultPriority;
isGlobal = _makeGlobal;
// build internal data structures
parseZipDirectory();
}
示例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: main
int main (int argc, char *argv[])
{
const int n = (1 < argc) ? atoi(argv[1]) : 1000000; // number of
// iterations
#if defined( STDIO )
FILE * target;
target = stdout;
if (2 < argc) { // place output in file
target = fopen( argv[2], "w" );
}
#else // for both iostreams libs
ofstream target;
ostream* op = &cout;
if (2 < argc) { // place output in file
target.open(argv[2]);
op = ⌖
}
ostream& out = *op;
#endif
int i; // for-loop variable
// output command for documentation:
#if defined( STDIO )
for (i = 0; i < argc; ++i)
fprintf( target, "%s ", argv[i]) ;
fprintf( target, "\n" );
#else
for (i = 0; i < argc; ++i)
out << argv[i] << " ";
out << "\n";
#endif
std::vector<T> v; // holds elapsed time of the tests
#if !defined( STDIO)
#if defined (CLASSIC)
// non-synchronized I/O is the default
#else
out.sync_with_stdio (false); // must be called before any output
#endif
#endif
// seed the random number generator
srand( clock() );
clock_t t = clock();
if (t == clock_t(-1))
{
#if defined( STDIO )
fprintf( stderr, "sorry, no clock\n" );
#else
cerr << "sorry, no clock\n";
#endif
exit(1);
}
#if defined( STDIO )
t = clock();
for (i = 0; i != n; ++i)
{
fprintf ( target, "%d ", i);
}
v.push_back(T("output integers to stdio ", clock() - t));
t = clock();
for ( i = 0; i != n; ++i)
{
fprintf ( target, "%x ", i);
}
v.push_back(T("output hex integers to stdio ", clock() - t));
if (clock() == clock_t(-1))
{
fprintf ( stderr, "sorry, clock overflow\n" );
exit(2);
}
// output results
fprintf ( stderr, "\n" );
for (i = 0; static_cast<size_t>(i)<v.size(); i++)
fprintf( stderr, "%s :\t%f seconds\n", v[i].s, v[i].t /CLOCKS_PER_SEC );
#else
t = clock();
for ( i = 0; i != n; ++i)
{
out << i << ' ';
}
v.push_back(T("output integers (sync = false) ", clock() - t));
out << hex;
t = clock();
for ( i = 0; i != n; ++i)
{
out << i << ' ';
}
v.push_back(T("output hex integers (sync = false) ", clock() - t));
//.........这里部分代码省略.........