本文整理汇总了C++中sequence::current方法的典型用法代码示例。如果您正苦于以下问题:C++ sequence::current方法的具体用法?C++ sequence::current怎么用?C++ sequence::current使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sequence
的用法示例。
在下文中一共展示了sequence::current方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_items
// **************************************************************************
// bool test_items(sequence& test, size_t s, size_t i, double items[])
// The function determines if the test sequence has the correct items
// Precondition: The size of the items array is at least s.
// Postcondition: A return value of true indicates that test.current()
// is equal to items[i], and after test.advance() the result of
// test.current() is items[i+1], and so on through items[s-1].
// At this point, one more advance takes the cursor off the sequence.
// If any of this fails, the return value is false.
// NOTE: The test sequence has been changed by advancing its cursor.
// **************************************************************************
bool test_items(sequence& test, size_t s, size_t i, double items[])
{
bool answer = true;
cout << "The cursor should be at item [" << i << "]" << " of the sequence\n";
cout << "(counting the first item as [0]). I will advance the cursor\n";
cout << "to the end of the sequence, checking that each item is correct...";
cout.flush( );
while ((i < s) && test.is_item( ) && (test.current( ) == items[i]))
{
i++;
test.advance( );
}
if ((i != s) && !test.is_item( ))
{ // The test.is_item( ) function returns false too soon.
cout << "\n Cursor fell off the sequence too soon." << endl;
answer = false;
}
else if (i != s)
{ // The test.current( ) function returned a wrong value.
cout << "\n The item [" << i << "] should be " << items[i] << ",\n";
cout << " but it was " << test.current( ) << " instead.\n";
answer = false;
}
else if (test.is_item( ))
{ // The test.is_item( ) function returns true after moving off the sequence.
cout << "\n The cursor was moved off the sequence,";
cout << " but is_item still returns true." << endl;
answer = false;
}
cout << (answer ? "Passed." : "Failed.") << endl;
return answer;
}
示例2: show_list
void show_list(sequence<T> src)
// Pre: (none)
// Post: The items of src are printed to cout (one per line).
{
for ( src.start(); src.is_item(); src.advance() )
cout << src.current() << " ";
}
示例3: show_sequence
void show_sequence(sequence src)
{
for ( src.start(); src.is_item(); src.advance() )
cout << src.current() << endl;
}
示例4: show_list
void show_list(sequence<T> src)
{
for ( src.start(); src.is_item(); src.advance() )
cout << src.current() << " ";
}
示例5: show_sequence
void show_sequence(sequence display)
// Library facilities used: iostream
{
for (display.start( ); display.is_item( ); display.advance( ))
cout << display.current( ) << endl;
}