本文整理汇总了C++中std::getline方法的典型用法代码示例。如果您正苦于以下问题:C++ std::getline方法的具体用法?C++ std::getline怎么用?C++ std::getline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::getline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialise
void QuantitationInfo::initialise ()
{
GenIFStream fromFile ( MsparamsDir::instance ().getParamPath ( "quan.txt" ) );
string line;
while ( getline ( fromFile, line ) ) {
if ( line.length () != 0 && line [0] != '#' ) {
name.push_back ( line );
string n = name.back ();
StringVector sv;
for ( ; ; ) {
string modificationName;
getline ( fromFile, modificationName );
if ( modificationName [0] == '>' ) {
if ( sv.empty () && n != "Label:15N" ) {
ErrorHandler::genError ()->error ( "No quantitation modifications specified for quantitation type " + n + " in file quan.txt.\n" );
}
break;
}
else
sv.push_back ( modificationName );
}
singQuanInfo [n] = sv;
}
}
}
示例2: AddRecipe
void AddRecipe(map<string, vector<string> >& recipes)
{
string name, ingredient, garbage;
//Clear cin.
//Fixes a bug where getline was assiging empty strings with no user input
//to name & ingredient.
getline(cin, garbage, '\n');
cout << "\n----------\n"
<< "ADD RECIPE\n"
<< "----------\n\n"
<< "Enter the name for the recipe: ";
getline(cin, name, '\n');
cout << endl;
do
{
cout << "Enter ingredient and amount, E.G. \"1 cup flour\"\n"
<< "or type \"done\" when done.\n";
getline(cin, ingredient, '\n');
if (ingredient != "done")
{
//Add to the map.
recipes[name].push_back(ingredient);
cout << "\nAdded \"" << ingredient << "\".\n\n";
}
} while (ingredient != "done");
cout << endl;
}
示例3: read_spec
void read_spec(vector<Event*>& events) {
ifstream es("EVENT.SPEC");
if (!es) {
cerr << "Cannot open EVENT.SPEC file" << endl;
exit(1);
}
string line, section, name;
int nfields;
while ( getline(es, line) ) {
if ( line[0] == '@' ) {
// -- new section
section = line.substr(2);
} else if ( line[0] != '#' && line[0] != '\0' ) {
// -- new event
name = line;
es >> nfields;
skip_line(es);
Event* event = new Event(name, nfields, section);
for (int i=0; i<nfields; ++i) {
Field field;
getline(es, event->fields[i].type);
getline(es, event->fields[i].fname);
getline(es, event->fields[i].descr);
}
events.push_back(event);
section = "";
}
}
示例4: main
int main()
{
const size_t count = 100;
string names[count];
string ages[count];
string firstname;
string secondname;
for(size_t i = 0 ; i<count ; i++)
{
cout << endl << "Enter a first name or press Enter to end: ";
getline(cin, firstname, '\n');
if(firstname.empty())
{
listnames(names, ages, i);
cout << "Done!!" << endl;
return 0;
}
cout << "Enter a second name: ";
getline(cin, secondname, '\n');
names[i] = firstname + ' ' + secondname;
cout << "Enter " + firstname + "'s age: ";
getline(cin, ages[i], '\n');
}
cout << "No space for more names." << endl;
listnames(names, ages, count);
return 0;
}
示例5: repl
void repl(shared_ptr< environment > env_p)
{
cout << prompt;
string line;
while (getline(cin, line)) {
string code = line;
stack< int > open_parens;
while (!paren_match(code) || !quot_match(code)) {
int ind = indent(line, open_parens);
cout << string(ind + prompt.length(), ' ');
if (!getline(cin, line)) {
cout << bye;
return;
}
if (quot_match(code))
code.push_back(' ');
code += line;
}
vector< string > parts = split(code);
for (auto it = begin(parts); it + 1 < end(parts); ++it)
eval(parse(*it), env_p);
if (!parts.empty()) {
value retval = eval(parse(parts.back()), env_p);
apply_visitor(return_value_visitor(), retval);
}
cout << prompt;
}
cout << bye;
}
示例6: main
int main(void) {
int num_cases;
cin >> num_cases >> ws;
string line;
while (num_cases--) {
int num_computers;
cin >> num_computers >> ws;
union_find uf(num_computers);
getline(cin, line);
int good = 0, bad = 0;
while (!line.empty()) {
stringstream ss(line);
char c;
int first;
int second;
ss >> c >> first >> second;
if (c == 'c')
uf.union_set(first-1, second-1);
if (c == 'q')
if (uf.find_set(first-1) == uf.find_set(second-1))
good ++;
else
bad++;
getline(cin, line);
}
cout << good << "," << bad << endl;
if (num_cases)
cout << endl;
}
}
示例7: in_file
//---------------------------------------------------------------------------
void __fastcall TMainForm::LoadFromFile(const AnsiString FileName)
{
std::ifstream in_file(FileName.c_str());
if (!in_file)
{
ShowError("File cannot be opened!");
return;
}
switch (FileName[FileName.Length()])
{
case 'm':
case 'M':
in_file >> rows >> cols >> lyrs;
if (rows > MAX_DIM || cols > MAX_DIM || lyrs > MAX_DIM)
{
ShowError(("An array dimension cannot be more than " +
IntToStr(MAX_DIM)).c_str());
return;
}
pgcProblems->ActivePage = tbsMatrix;
udwRows->Position = rows;
udwColumns->Position = cols;
udwLayers->Position = lyrs;
udwLayer->Position = 1;
for (int k = 0; k < lyrs; k++)
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
in_file >> a[i][j][k];
ShowMatrix();
break;
case 'l':
case 'L':
pgcProblems->ActivePage = tbsStudents;
std::string tmps;
StudList->Items->BeginUpdate();
StudList->Clear();
for (;;)
{
using std::getline;
getline(in_file, tmps);
if (!(tmps.length() && in_file)) goto ready;
TListItem *Item = StudList->Items->Add();
Item->Caption = tmps.c_str();
for (int i = 0; i < 8; i++)
{
getline(in_file, tmps);
Item->SubItems->Add(tmps.c_str());
}
while (in_file.get() != '\n')
if (!in_file) goto ready;
}
ready:
StudList->Items->EndUpdate();
break;
}
}
示例8: name
void name()
{
string name1, name2;
cout << "Enter your first name: ";
getline(cin,name1);
cout << "Enter your last name: ";
getline(cin,name2);
name1 = name2 + ", " + name1;
cout << "Here's the information in a single string " << name1 << endl;
}
示例9: readImageData
void readImageData( istream& is, cv::Mat_<cv::Vec3b>& cimg, cv::Mat_<cv::Vec3f>& points, cv::Mat_<float>& dimg)
{
string ln;
getline( is, ln);
istringstream iss(ln);
cv::Size imgSz;
iss >> imgSz.height >> imgSz.width;
cimg = cv::Mat_<cv::Vec3b>( imgSz);
points = cv::Mat_<cv::Vec3f>( imgSz);
dimg = cv::Mat_<float>( imgSz);
const int sz = imgSz.width * imgSz.height;
const int pxlChunk = 3*sizeof(float) + 3*sizeof(byte);
const int totalBytes = sz * pxlChunk;
char* buff = (char*)malloc( totalBytes);
int readBytes = 0;
while ( readBytes < totalBytes)
{
is.read( &buff[readBytes], totalBytes-readBytes);
const int numBytesRead = is.gcount();
if ( numBytesRead <= 0)
break;
readBytes += numBytesRead;
} // end while
assert( readBytes == totalBytes);
for ( int i = 0; i < sz; ++i)
{
int j = i * pxlChunk; // Offset into read in buffer
// Read in points (with respect to origin)
cv::Vec3f p( *(float*)&buff[j], // X
*(float*)&buff[j+sizeof(float)], // Y
*(float*)&buff[j+2*sizeof(float)]); // Z (depth)
j += 3*sizeof(float); // Skip to colour bytes
cv::Vec3b c( (byte)buff[j], (byte)buff[j+1], (byte)buff[j+2]);
const int row = i / imgSz.width; // Integer division
const int col = i % imgSz.width;
cimg.at<cv::Vec3b>(row,col) = c;
points.at<cv::Vec3f>(row,col) = p;
dimg.at<float>(row,col) = p[2]; // Depth is just the Z value
} // end for
free(buff);
getline( is, ln); // Read end of line
} // end readImageData
示例10: getNext
bool XMLIStreamList::getNext ( string& s )
{
bool flag = false;
string line;
while ( getline ( ist, line ) ) {
if ( line.find ( nameStart ) != string::npos ) { // start tag found
while ( getline ( ist, line ) ) {
if ( line.find ( nameEnd ) != string::npos ) return true; // end tag found
s += line;
}
}
}
return false;
}
示例11: ReadUNetworkFromNetFile
void scn::ReadUNetworkFromNetFile(UNetwork<>::pNetwork &network,char * path)
{
using std::getline;
using std::string;
using std::cout;
using std::endl;
std::ifstream infile(path);
UGraph::pGraph graph(new UGraph());
network.reset(new UNetwork<>(graph));
string line;
string temp;
std::stringstream ss;
//read header
while(getline(infile, line))
{
ss.str(line);
if(ss>>temp && temp == "*Vertices")
{//read nodes
size_t numberOfNodes;
ss>>numberOfNodes;
size_t index;
string flag;
double x,y,z;
for(size_t i = 0; i < numberOfNodes; i++)
{
getline(infile, line);
ss.clear();
ss.str(line);
if(ss>>index>>flag>>x>>y>>z)//read content
{
graph->AddNode(index - 1);
network->SetNodePosition(index - 1, x, y, z);
}
}
assert(numberOfNodes == graph->GetNumberOfNodes());
}
else if(line == "*Edges")
{//read edge
size_t indexOfNode1, indexOfNode2;
double weight;
while(getline(infile, line))
{
ss.clear();
ss.str(line);
if(ss>>indexOfNode1>>indexOfNode2>>weight)
graph->AddEdge(indexOfNode1 - 1, indexOfNode2 -1);
}
}
示例12: getVersionFromPPXMLFile
string getVersionFromPPXMLFile ( const string& filename )
{
GenIFStream ist ( filename );
string line;
getline ( ist, line );
getline ( ist, line ); // Version is stored on the second line
int start = line.find ( "Version" ) + 8;
if ( start != string::npos ) {
int end = line.find ( "?", start );
if ( end != string::npos ) {
return line.substr ( start, end - start );
}
}
return "";
}
示例13: fileName
FileStopper(const string &languageCode) :
Xapian::SimpleStopper(),
m_languageCode(languageCode),
m_stopwordsCount(0)
{
if (languageCode.empty() == false)
{
ifstream inputFile;
string fileName(PREFIX);
fileName += "/share/pinot/stopwords/stopwords.";
fileName += languageCode;
inputFile.open(fileName.c_str());
if (inputFile.good() == true)
{
string line;
// Each line is a stopword
while (getline(inputFile, line).eof() == false)
{
add(line);
++m_stopwordsCount;
}
}
inputFile.close();
#ifdef DEBUG
cout << "FileStopper: " << m_stopwordsCount << " stopwords for language code " << languageCode << endl;
#endif
}
}
示例14: main
int main()
{
bool repeat = 1;
while (repeat == 1)
{
//main variables
int whichOne;
string inStr = "";
cout << " Checking for PALINDROME or REVERSING" << endl;
cout << "1- Iterative word or phrase REVERSE for just $1" << endl;
cout << "2- Recursive word or phrase REVERSE for only $2" << endl;
cout << "3- Iterative PALINDROME check, and word or phrase REVERSE a mere $5" << endl;
cout << "4- Grand slam: Recursive PALINDROME check, and word or phrase REVERSE $40" << endl;
cout << "Please enter a word or phrase (alphanumeric only, no punctuation): " << endl;
getline(cin, inStr);
//function sanitizes numeric input
whichOne = getInt();
//main switch statement
picker(whichOne, inStr);
//check for repeat
cout << "Would you like another one?" << endl;
cout << "0- no / 1- yes" << endl;
cin >> repeat;
}
return 0;
}
示例15: main
int main(void) {
std::ios_base::sync_with_stdio (false);
size_t n;
cin >> n >> ws;
vvs graph(n, vs());
dfs_num.resize(n, 0);
parent.resize(n, -1);
finished = false;
a = b = c = -1;
string line;
for (size_t line_cnt = 0; line_cnt < n; line_cnt++) {
getline(cin, line);
for (size_t char_cnt = 0; char_cnt < n; char_cnt++) {
if (line.at(char_cnt) == '1')
graph[line_cnt].push_back(char_cnt);
}
}
for (size_t counter = 0; counter < n; counter++)
if (!dfs_num[counter])
dfs(graph, counter);
if (a >= 0)
cout << a+1 << " " << b+1 << " " << c+1 << endl;
else
cout << -1 << endl;
return 0;
}