本文整理汇总了C++中istream::getline方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::getline方法的具体用法?C++ istream::getline怎么用?C++ istream::getline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类istream
的用法示例。
在下文中一共展示了istream::getline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
/*
* TRADE_TYPE
*/
void TRADE_TYPE_ROW::Load(istream &file)
{
char buf[1024];
UINT is_market;
UINT is_sell;
file.getline(buf, sizeof(buf));
if (file.eof()) {
return;
}
int rc = sscanf(buf, "%[^\t]\t%[^\t]\t%d\t%d",
TT_ID, TT_NAME, &is_sell, &is_market);
/* handle integer to boolean conversion. We can't use TT_* directly */
/* in the sscanf above since sscanf doesn't know how to deal with */
/* boolean variables for storage. */
TT_IS_SELL = (is_sell == 1 ? true : false);
TT_IS_MRKT = (is_market == 1 ? true : false);
if (rc != 4) {
std::ostringstream strm;
strm << "TRADE_TYPE_ROW::Load only loaded " << rc << " values from line";
throw std::runtime_error(strm.str());
}
#if 0
file>>TT_ID>>ws;
file.get(TT_NAME, sizeof(TT_NAME), '\t');
file>>ws;
file>>TT_IS_SELL;
file>>TT_IS_MRKT;
#endif
}
示例2:
/** Constructs a MapLine object by parsing a single mapline from the given stream. */
MapLine::MapLine (istream &is)
: _sfd(0), _fontindex(0), _slant(0), _bold(0), _extend(1)
{
char buf[256];
is.getline(buf, 256);
parse(buf);
}
示例3: rmuser_command
static void rmuser_command(ostream &out, istream &in)
{
if (get_access_level() < ADMIN_ACCESS_LEVEL)
{
cout << "You must be logged in with administrator privileges\n"
"(access level " << ADMIN_ACCESS_LEVEL
<< " or higher) to add users." << endl ;
return ;
}
char username[200] ;
out << "Name of user to remove: " << flush ;
in.ignore(1000,'\n') ;
in.getline(username,sizeof(username)) ;
if (!retrieve_userinfo(username))
{
cout << "No such user!" ;
return ;
}
if (remove_user(username))
cout << "User information file updated." << endl ;
else
cout << "User information file update failed!" << endl ;
return ;
}
示例4: while
// Initialize the zscores with means and standard dev, and other phoneme info
ZPhoneme::ZPhoneme(istream& zs )
{
char line[255];
while(zs.getline(line,sizeof(line)))
{
int pos=0;
// Check if it's a comment
sscanf(line," ##%n",&pos);
if (pos==0)
{
double avg;
double std;
char phonename[255];
// Skip empty lines or non conform ones
if (sscanf(line," %s %lf %lf %n", phonename, &avg, &std, &pos) == 3)
{
ZPhone zf;
zf.zratio=Zratio(avg,std);
zf.flags= &line[pos];
insert( ZPhoneme::value_type(Phoneme(phonename),zf) );
}
}
}
}
示例5: read_input
void read_input(istream& input_stream, char* filename){
// returns number of examples sets read
char* s = new char[MAXCHAR];
char next;
next = input_stream.peek();
if(next == EOF){
// set stream to eof
next = input_stream.get();
};
while(! input_stream.eof()){
if('#' == next){
// ignore comment
input_stream.getline(s,MAXCHAR);
}
else if('\n' == next){
// ignore newline
next = input_stream.get();
}
else if('@' == next){
// new section
input_stream >> s;
if(0==strcmp("@parameters",s)){
// read parameters
if(parameters == 0){
parameters = new parameters_c();
input_stream >> *parameters;
}
else{
cout <<"*** ERROR: Parameters multiply defined"<<endl;
throw input_exception();
};
}
示例6: getSLine
string getSLine(istream &str)
{ char line[1024];
str.getline(line, 1024);
if (str.gcount()==1024-1)
raiseError("line too long");
return line;
}
示例7: parseline
int parseline(istream& inp, int Order,ngram& ng,float& prob,float& bow)
{
const char* words[1+ LMTMAXLEV + 1 + 1];
int howmany;
char line[MAX_LINE];
inp.getline(line,MAX_LINE);
if (strlen(line)==MAX_LINE-1) {
cerr << "parseline: input line exceed MAXLINE ("
<< MAX_LINE << ") chars " << line << "\n";
exit(1);
}
howmany = parseWords(line, words, Order + 3);
if (!(howmany == (Order+ 1) || howmany == (Order + 2)))
assert(howmany == (Order+ 1) || howmany == (Order + 2));
//read words
ng.size=0;
for (int i=1; i<=Order; i++)
ng.pushw(strcmp(words[i],"<unk>")?words[i]:ng.dict->OOV());
//read logprob/code and logbow/code
assert(sscanf(words[0],"%f",&prob));
if (howmany==(Order+2))
assert(sscanf(words[Order+1],"%f",&bow));
else
bow=0.0; //this is log10prob=0 for implicit backoff
return 1;
}
示例8: extractParams
void extractParams(istream& stream, vector<string>& params)
{
char line[400]; // space for a line
params.clear(); // reset the params
stream.getline(line, 400); // read a full line
string loadLine = line; // line for tokenizing
int commaPos, prevPos = 0; // position of commas
do
{
commaPos = loadLine.find(',', prevPos); // find next comman position
// extract from previous comma to current comma as one string
string param = loadLine.substr(prevPos, commaPos==string::npos ? commaPos : commaPos-prevPos);
// trim the string (no white space before or after)
param = trim(param);
// include the param in result
params.push_back(param);
prevPos = commaPos+1;
}
while (commaPos != string::npos);
}
示例9: partir
// Parte un fichero en varios
void partir(istream & entrada, char *nombreFichero, int lineas) {
// Atributos
ofstream fileSalida;
ofstream fileControl;
string nomFicheroCtrl = "." + string(nombreFichero) + ".ctrl";
int num_ficheros = 0;
int num_linea = 0;
const int BUFF_SIZE = 500;
char linea[BUFF_SIZE];
// Recorremos las lineas
while (entrada.getline(linea, BUFF_SIZE)) {
// Incrementamos el contador
num_linea++;
// Si hemos sobrepasado las lineas maximas...
if (num_linea >= lineas) {
num_linea = 0; //Reseteamos el numero de lineas
num_ficheros++;
fileSalida.close(); // Cerramos el archivo
string nomFichero = string(nombreFichero) + "_" + to_string(num_ficheros) ;
// Abrimos otro archivo
fileSalida.open (nomFichero);
if (!fileSalida) {
cerr << "Error: no puedo crear el fichero " << nomFichero << endl;
exit(1); // Salimos con error
}
}
// Escribimos la linea
fileSalida << linea << endl;
}
// Cerramos el archivo
fileSalida.close();
// Creamos el fichero de control, lo escribimos y lo cerramos
fileControl.open (nomFicheroCtrl);
if (!fileControl) {
cerr << "Error: no puedo crear el fichero de control" << endl;
exit(1); // Salimos con error
}
fileControl << nombreFichero << endl;
fileControl << num_ficheros << endl;
fileControl.close();
}
示例10: load
void Monster::load(istream &in) {
Unit::load(in);
char buf[MAX_LEN_BUF];
//out << "#-------------------- class Monster" << endl;
in.getline(buf, MAX_LEN_BUF); // skip comment
}
示例11: getLineExt
//extends fstream::getline with check on exceeding the buffer size
std::streamsize getLineExt(istream& fin, char* buf)
{
fin.getline(buf, LINE_LEN);
std::streamsize bufLen = fin.gcount();
if(bufLen == LINE_LEN - 1)
throw LONG_LINE_ERR;
return bufLen;
}
示例12: read
void Motif::read(istream& motin) {
char line[200];
vector<int> c;
vector<int> p;
vector<bool> s;
// Read sites
// (don't add yet, as they will get screwed up by the column changes)
while(motin.getline(line, 200)) {
if(line[0] == '*') break;
strtok(line, "\t");
c.push_back(atoi(strtok(NULL, "\t")));
p.push_back(atoi(strtok(NULL, "\t")));
s.push_back(atoi(strtok(NULL, "\0")));
}
int motwidth = strlen(line);
columns.clear();
for(int i = 0; i < motwidth; i++) {
if(line[i] == '*') add_col(i);
}
// Add sites
sitelist.clear();
int num_sites = c.size();
for(int i = 0; i < num_sites; i++) {
assert(p[i] >= 0);
add_site(c[i], p[i], s[i]);
}
// Read MAP score
motin.getline(line, 200);
strtok(line, ":");
set_map(atof(strtok(NULL, "\0")));
// Read specificity
motin.getline(line, 200);
strtok(line, ":");
set_spec(atof(strtok(NULL, "\0")));
// Read sequence cutoff
motin.getline(line, 200);
strtok(line, ":");
set_seq_cutoff(atof(strtok(NULL, "\0")));
// Read expression cutoff
motin.getline(line, 200);
strtok(line, ":");
set_expr_cutoff(atof(strtok(NULL, "\0")));
// Read iteration found
motin.getline(line, 200);
strtok(line, ":");
set_iter(strtok(NULL, "\0"));
// Read dejavu
motin.getline(line, 200);
strtok(line, ":");
set_dejavu(atoi(strtok(NULL, "\0")));
}
示例13: utGetTokenInStream
std::string utGetTokenInStream(istream & stream, int maxLength, char delimiter)
{
assert(maxLength <= 1024);
char StringBuffer[1024];
eatwhite(stream);
stream.getline(StringBuffer, maxLength, delimiter);
return StringBuffer;
}
示例14: readFile
/***
IMP::
maze:
- It must have odd number of lines.
- Each line in the input must have odd number of characters and all lines must have the same length.
- Finally, it has to be a valid maze in the sense that all rooms are connected.
Once you convert an input into a maze, the size of the maze must be within the limits of the mazegen command.
*/
void readFile(istream& in) {
char* buf = new char[MAXBUFSIZE];
in.getline(buf,MAXBUFSIZE);
int linelength = strlen(buf);
while (!in.eof()) {
#ifdef DEBUG1
fprintf(stdout,"line read: %s\n",buf);
#endif
strcpy(linebuf[linebufcount++],buf);
in.getline(buf,MAXBUFSIZE);
int len = strlen(buf);
if(!in.eof()) {
if(linelength!=len) {
fprintf(stderr,"(malformed input file)-Not all lines are of the same length in input file %d != %d\n",linelength,len);
exit(-1);
}
}
}
#ifdef DEBUG1
fprintf(stdout,"EOF REACHED\n");
#endif
if(linebufcount%2==0) {
fprintf(stderr,"(malformed input file): even number of lines found\n");
exit(-1);
}
if(linebufcount==1) {
fprintf(stderr,"(malformed input file): just one line found in input\n");
exit(-1);
}
int widthtest = strlen(linebuf[0]);
if(widthtest%2==0) {
fprintf(stderr, "(malformed input file):even number of characters found on the input line\n");
exit(-1);
}
updateheightwidth();
}
示例15: newuser_command
static void newuser_command(ostream &out, istream &in)
{
if (get_access_level() < ADMIN_ACCESS_LEVEL)
{
cout << "You must be logged in with administrator privileges\n"
"(access level " << ADMIN_ACCESS_LEVEL
<< " or higher) to add users." << endl ;
return ;
}
char username[200] ;
char password[200] ;
FrObject *ulevel ;
int level ;
out << "New user's name: " << flush ;
in.ignore(1000,'\n') ;
in.getline(username,sizeof(username)) ;
out << "New password: " << flush ;
in.getline(password,sizeof(password)) ;
out << "User's access level: " << flush ;
in >> ulevel ;
if (ulevel && ulevel->numberp())
{
level = ulevel->intValue() ;
if (level < GUEST_ACCESS_LEVEL)
level = GUEST_ACCESS_LEVEL ;
else if (level > ROOT_ACCESS_LEVEL)
level = ROOT_ACCESS_LEVEL ;
}
else
level = GUEST_ACCESS_LEVEL ;
FrStruct *userinfo = retrieve_userinfo(username) ;
if (userinfo)
{
cout << "That user is already registered!" ;
return ;
}
userinfo = make_userinfo(username,password,level) ;
if (update_user(userinfo))
cout << "User information file updated." << endl ;
else
cout << "User information file update failed!" << endl ;
return ;
}