本文整理汇总了C++中stringstream::getline方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::getline方法的具体用法?C++ stringstream::getline怎么用?C++ stringstream::getline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::getline方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetColumn
int TablePaser::GetColumn(stringstream& ss_str, std::basic_istream<char>& in_put, string& column)
{
column = "";
if (ss_str.eof())
return -1;
char cur_char[2];
cur_char[1] = 0;
char separator = ' ';
if (ss_str.get(cur_char[0]).eof())
return 1;
if (cur_char[0] == ' ')
return 1;
else if (cur_char[0] == '"')
separator = '"';
else
column += string(cur_char);
while (1)
{
if (ss_str.eof())
{
if (separator == '"')
{
if (in_put.eof())
return 0;
column += string("\n\0");
ss_str.clear();
in_put.getline(LineData, LINE_DATA_MAX);
ss_str << LineData;
}
else
return 0;
}
ss_str.getline(LineData, 4096, separator);
column += LineData;
//column.append(LineData);
if (ss_str.eof())
continue;
if (separator == ' ')
return 1;
else if (separator == '"')
{
if (ss_str.eof())
return 0;
ss_str.get(cur_char[0]);
if (ss_str.eof())
return 1;
else if (cur_char[0] == ' ')
return 1;
else if (cur_char[0] != separator)
separator = ' ';
//column.push_back(cur_char);
column += string(cur_char);
}
}
return -1;
}
示例2: mem_logger_read_line
char* mem_logger_read_line()
{
static char buff[256];
buff[0] = 0;
if (oss.rdbuf()->in_avail())
oss.getline(buff, 256);
return buff;
}
示例3: analysis
//Create a report on all of the words in a stringstream.
void analysis(stringstream& ss) {
bool skip;
int num;
int wordCount = 0;
int blacklistCount = -1;
char* word = new char [WORD_SIZE];
char* temp = new char [WORD_SIZE];
char** blacklist;
stringstream outer, inner;
//Get a wordcount
while(ss.getline(word, numeric_limits<streamsize>::max(), ' ')) {
wordCount++;
}
//Setup the blacklist.
blacklist = new char* [wordCount];
for(int i=0; i<wordCount; i++) {
blacklist[i] = new char [WORD_SIZE];
*blacklist[i] = 'X';
}
//Setup the two loops needed for word reports.
outer.str(ss.str());
inner.str(ss.str());
//Print a report showing how many times each word appears.
while(outer.getline(word, numeric_limits<streamsize>::max(), ' ')) {
//Reset loop variables.
num = 0;
skip = false;
blacklistCount++;
inner.str(ss.str());
inner.seekp(0, inner.beg);
inner.seekg(0, inner.beg);
inner.clear();
//First see if the word is on the blacklist.
for(int i=0; i<wordCount; i++) {
if(strcmp(word, blacklist[i]) == 0) {skip = true; break;}
}
//Then abort the current word if it is.
if(skip == true) continue;
//Or count the number of times it occurs if not.
while(inner.getline(temp, numeric_limits<streamsize>::max(), ' ')) {
if(strcmp(word, temp) == 0) num++;
}
//And append the word to the blacklist.
strcpy(blacklist[blacklistCount], word);
cout << "The word " << setw(40) << left << word << " occurs " << num << " times.\n";
}
cout << "The number of words is: " << (wordCount - 1) << ".\n";
delete word;
delete temp;
for(int i=0; i<wordCount; i++) delete blacklist[i];
delete blacklist;
cout << endl;
return;
}
示例4: userFind
//Ask user what string they would like to find.
void userFind(stringstream& ss) {
extern char** environ;
char* choice = new char [WORD_SIZE];
char* word = new char [WORD_SIZE];
char* environment = new char [WORD_SIZE];
char temp;
int numLine = 0;
int count = 0;
int lines = 0;
streampos gpos, ppos;
ss.str(ss.str());
ss.seekp(0, ss.beg);
ss.seekg(0, ss.beg);
ss.clear();
//Ask user what string they would like to search for.
cout << "Please enter a string to search or \"END\" to quit. \n";
cin >> choice;
transform(choice, (choice + strlen(choice)), choice, ::toupper);
while(strcmp(choice, "END") != 0) {
//Search the stringstream for each occurance of the string.
while(ss.getline(word, WORD_SIZE, ' ')) {
transform(word, (word + strlen(word)), word, ::toupper);
if(strcmp(word, choice) == 0) {
//cout << "Word found!" << endl;
count++;
while(environ[lines]) {
transform(environ[lines], (environ[lines] + strlen(environ[lines])), environment, ::toupper);
if(strstr(environment, word)) cout << environ[lines] << endl;
lines++;
}
//Incrememnt numLine for each newline character we find.
//And print out the corresponding line.
}
}
//Then print out how many times the string appeared.
cout << "Found " << count << " results!\n";
cout << endl;
cout << "Please enter a string to search or \"END\" to quit. \n";
cin >> choice;
transform(choice, (choice + strlen(choice)), choice, ::toupper);
ss.str(ss.str());
ss.seekp(0, ss.beg);
ss.seekg(0, ss.beg);
ss.clear();
count = 0;
}
//delete environment;
delete choice;
delete word;
return;
}