2016-04-23 73 views
0

我正在使用堆栈和队列进行作业的整个回文程序。我们的教授让我们编写堆栈并从头开始排队,只针对字符串。我正在从文件中读取文本并确定是否是句子回文。我显然需要将每个字符推入堆栈和队列,但是,如何将字符推入接受字符串作为参数的堆栈?将char转换为堆栈的字符串<string>

//get data from txt file 
void getData(Stack &myStack, Queue &myQueue) 
{ 
ifstream infile; 

string temp; 
int i = 0; 

infile.open("palindrome.txt"); 

if (!infile) 
{ 
    cout << "The file failed to open." << endl; 
    exit(-1); 
} 

while (getline(infile, temp)) 
{ 

    //remove spaces form sentences 
    temp.erase(remove_if(temp.begin(), temp.end(), ::isspace),temp.end()); 

//need to push each character into stack and queue here 
//there are 5 sentences total in the file to check 


    i++; 


} 
+0

可能重复:http://stackoverflow.com/questions/11474147/most-优雅的路到初始化-A-串上带有一个单字符从-另一个-STR – Unimportant

回答