本文整理汇总了C++中StringStack类的典型用法代码示例。如果您正苦于以下问题:C++ StringStack类的具体用法?C++ StringStack怎么用?C++ StringStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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: _ctp_end_brackets
inline void _ctp_end_brackets(POSTFIX &postfix, StringStack &oper_stack)
{
while(oper_stack.getSize())
{
if(oper_stack.get_last()=="("){
oper_stack.remove();
break;
}
String s;
s=oper_stack.get_last();
oper_stack.remove();
if(isalpha(s[0])) {
//don't worry: this seems allright!!!
String name;
name="'";
name+=s;
postfix.add(name);
}else{
postfix.add(s);
}
}
}
示例3: reverse_stack
void reverse_stack(StringStack &from, StringStack &to){
while(from.get_top_position()){
to.add(from.get_last());
from.remove();
}
}
示例4: 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;
} ///:~
示例5: 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();
}
示例6: 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;
}
} ///:~
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
} ///:~
示例10: 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;
}
示例11: 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);
}
示例12: doType
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, StringBuffer& buf)
{
const char* typeName = type->queryName();
if (type->isComplexType())
{
if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
{
//DBGLOG("Recursive type: %s, ignored", type->queryName());
}
else
{
int flds = type->getFieldCount();
for (int i=0; i<flds; i++)
{
const char* fldName = type->queryFieldName(i);
buf.appendf("<%s>", fldName);
if (typeName)
parent.push_back(typeName);
doType(parent,indent+1,fldName,type->queryFieldType(i),buf);
buf.appendf("</%s>", fldName);
if (typeName)
parent.pop_back();
}
}
}
else if (type->isArray())
{
if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end())
{
//DBGLOG("Recursive type: %s, ignored", type->queryName());
}
else
{
const char* itemName = type->queryFieldName(0);
IXmlType* itemType = type->queryFieldType(0);
if (typeName)
parent.push_back(typeName);
for (int i=0; i<m_items; i++)
{
buf.appendf("<%s>", itemName);
doType(parent,indent+2,itemName, itemType, buf);
buf.appendf("</%s>", itemName);
}
if (m_ecl2esp)
buf.appendf("<%s/>", itemName);
if (typeName)
parent.pop_back();
}
}
else
{
//TODO: handle restriction etc
if (strcmp(typeName,"string")==0) // string type: [tag-typeName]
{
if (m_gx)
buf.append("*** MISSING ***");
else
if (m_ecl2esp)
buf.append("[?]");
else
buf.appendf("[%s]", tag);
}
else
setDefaultValue(buf,type,tag);
}
}
示例13: ScreenUpdates_Enable
void ScreenUpdates_Enable (void)
{
ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
g_wait_stack.pop_back();
if (g_wait_stack.empty()) {
map::AutoSaver().startTimer();
gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
destroy_floating_window(g_wait.m_window);
g_wait.m_window = 0;
} else if (GTK_WIDGET_VISIBLE(g_wait.m_window)) {
gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
ScreenUpdates_process();
}
}
示例14: warnf
const char *execute(S32 argc, const char *argv[])
{
#ifdef TORQUE_MULTITHREAD
if(isMainThread())
{
#endif
Namespace::Entry *ent;
StringTableEntry funcName = StringTable->insert(argv[0]);
ent = Namespace::global()->lookup(funcName);
if(!ent)
{
warnf(ConsoleLogEntry::Script, "%s: Unknown command.", argv[0]);
// Clean up arg buffers, if any.
STR.clearFunctionOffset();
return "";
}
return ent->execute(argc, argv, &gEvalState);
#ifdef TORQUE_MULTITHREAD
}
else
{
SimConsoleThreadExecCallback cb;
SimConsoleThreadExecEvent *evt = new SimConsoleThreadExecEvent(argc, argv, false, &cb);
Sim::postEvent(Sim::getRootGroup(), evt, Sim::getCurrentTime());
return cb.waitForResult();
}
#endif
}
示例15: dSprintf
//------------------------------------------------------------------------------
const char *execute(SimObject *object, S32 argc, const char *argv[], bool thisCallOnly)
{
static char idBuf[16];
if(argc < 2)
return "";
// [neo, 10/05/2007 - #3010]
// Make sure we don't get recursive calls, respect the flag!
// Should we be calling handlesMethod() first?
if( !thisCallOnly )
{
ICallMethod *com = dynamic_cast<ICallMethod *>(object);
if(com)
com->callMethodArgList(argc, argv, false);
}
if(object->getNamespace())
{
dSprintf(idBuf, sizeof(idBuf), "%d", object->getId());
argv[1] = idBuf;
StringTableEntry funcName = StringTable->insert(argv[0]);
Namespace::Entry *ent = object->getNamespace()->lookup(funcName);
if(ent == NULL)
{
//warnf(ConsoleLogEntry::Script, "%s: undefined for object '%s' - id %d", funcName, object->getName(), object->getId());
// Clean up arg buffers, if any.
STR.clearFunctionOffset();
return "";
}
// Twiddle %this argument
const char *oldArg1 = argv[1];
dSprintf(idBuf, sizeof(idBuf), "%d", object->getId());
argv[1] = idBuf;
SimObject *save = gEvalState.thisObject;
gEvalState.thisObject = object;
const char *ret = ent->execute(argc, argv, &gEvalState);
gEvalState.thisObject = save;
// Twiddle it back
argv[1] = oldArg1;
return ret;
}
warnf(ConsoleLogEntry::Script, "Con::execute - %d has no namespace: %s", object->getId(), argv[0]);
return "";
}