本文整理汇总了C++中StringStack::push方法的典型用法代码示例。如果您正苦于以下问题:C++ StringStack::push方法的具体用法?C++ StringStack::push怎么用?C++ StringStack::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringStack
的用法示例。
在下文中一共展示了StringStack::push方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
main(void)
{
StringStack stack;
//用初始化构造函数构造一个字符串常量数组
MyString my[] = {
MyString("hello"),
MyString("programmer"),
MyString("It`s a nice day"),
MyString("keep do it"),
MyString("Never give up")
};
//字符串常量指针入栈,注意存的是指针,所以采用取地址操作
for (int i = 0; i < sizeof my / sizeof *my; i++) {
stack.push(&my[i]);
}
//返回的是一个常量对象指正,故只有常量成员函数才能调用
const MyString* cm;
for (int i = 0; i < sizeof my / sizeof *my; i++) {
//注意此处cm是指针,直接进行赋值即可不需要进行取地址操作
cm = stack.pop();
cm->print();
}
return 0;
}
示例2: main
int main() {
StringStack ss;
for(int i = 0; i < iCsz; i++)
ss.push(&iceCream[i]);
const string* cp;
while((cp = ss.pop()) != 0)
cout << *cp << endl;
} ///:~
示例3: main
int main() {
StringStack ss;
for (int i = 0; i < iCsz; i++)
ss.push(&iceCream[i]);
const MyString *cp;
while((cp = ss.pop()) != NULL)
cp->print();
}
示例4: main
/** Test-driving code for StringStacks.
*/
int main() {
StringStack* testStack = new StringStack();
cout << "Pushing \"AAA\" ... "; //no "endl", keep next on same line
testStack->push("AAA");
cout << "Pushing \"BBB\" ... " << endl;
testStack->push("BBB");
cout << "Size is now " << testStack->size() << endl;
testStack->pop();
cout << "Pop---size is now " << testStack->size() << endl;
string c = testStack->pop();
cout << "I popped the string \""
<< c << "\", size now " << testStack->size() << endl;
cout << "Can I pop again?" << endl;
string d = testStack->pop();
cout << "Oops! I got: \"" << d << "\"" << endl;
//delete(testStack);
StringStack test2 = (*testStack);
return (0);
}
示例5: main
int main() {
StringStack ss;
for (int i = 0; i < iCsz; i++)
ss.push(new MyString(&iceCream[i]));
const MyString* cp;
while ((cp = ss.pop()) != 0) {
cp->print();
delete cp;
}
} ///:~
示例6: main
int main() {
StringStack ss;
myString* ms;
for(int i = 0; i < iCsz; i++){
ms = new myString(iceCream[i]);
ss.push(ms);
}
const myString* cp;
while((cp = ss.pop()) != 0)
cout << cp->str << endl;
}
示例7: main
int main(int argc, char const *argv[])
{
StringStack SS;
for (int i = 0; i < ICsz; ++i)
{
SS.push(iceCream[i]);
}
const char* cp;
while((cp = SS.pop()) != 0)
cout << cp << endl;
return 0;
}
示例8: main
int main() {
ifstream in("InheritStack.cpp");
assure(in, "InheritStack.cpp");
string line;
StringStack textlines;
while(getline(in, line))
textlines.push(new string(line));
string* s;
while((s = textlines.pop()) != 0) { // No cast!
cout << *s << endl;
delete s;
}
} ///:~
示例9: DoDirs
bool CommandLineInterface::DoDirs()
{
StringStack tempStack;
std::string cwd;
if (!GetCurrentWorkingDirectory(cwd))
{
return false;
}
// cwd is top of stack
if (m_RawOutput)
{
m_Result << cwd;
}
else
{
AppendArgTagFast(sml_Names::kParamDirectory, sml_Names::kTypeString, cwd);
}
// print rest of stack making a new one
while (m_DirectoryStack.size())
{
if (m_RawOutput)
{
m_Result << ' ' << m_DirectoryStack.top();
}
else
{
AppendArgTagFast(sml_Names::kParamDirectory, sml_Names::kTypeString, m_DirectoryStack.top());
}
tempStack.push(m_DirectoryStack.top());
m_DirectoryStack.pop();
}
// put the old stack back together
while (tempStack.size())
{
m_DirectoryStack.push(tempStack.top());
tempStack.pop();
}
return true;
}