2016-04-23 67 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

回答