2017-08-03 65 views
0

嗨,我有以下代碼,我想通過與循環創建所有可能的變化的字符串列表,我有一個問題,瞭解如何打印字符串,包括所有的「 「並且, 是這樣的:轉義字符在c + +和for循環

"","""polo-M-GRE""","polo-M-GRE","Products","Unit",0,"","","","Size","Medium",0,0.0,0.0,0.0,"","","","","","" 
"","","","","","","","","","Colour","TTR",0,0.0,0.0,0.0,"","","","","","" 

任何幫助將受到歡迎表示感謝。

#include <cstdlib> 
#include <iostream> 
#include <string> 
using namespace std; 

/* 
* 
*/ 
int main(int argc, char** argv) { 

    string size_attr[] = {"Extra Small","Small","Medium","Large","Extra Large"}; 
    string size_abv[]={"XS","S","M","L","XL"}; 
    string color_attr[]={"Red","Green","Blue","Black","White"}; 
    string color_abv[]={"RED","GRE","BLU","BLA","WHI"}; 
    for (int i = 0; i <= (sizeof (size_attr)/sizeof (*size_attr)); i++) { 
     for (int y = 0; y <= 4; y++) { 
      cout << "\"\""",""""polo-M-RED""","polo-M-RED","Products","Unit",0,"","","","Size","Medium",0,0.0,0.0,0.0,"","","","","","" 
"","","","","","","","","","Colour","Red",0,0.0,0.0,0.0,"","","","","",""<< endl; 
     } 
    } 
     return 0; 
} 
+2

不是真的知道你是問什麼。你根本沒有使用你的數組變量,也不清楚你的輸出需要什麼樣子。你想寫一個CSV文件?至少在外部循環中,<='也被錯誤地使用。目前還不清楚內部循環是什麼意思。 –

+0

逗號運算符不會執行您認爲它在此處執行的操作。 –

+0

您需要或者爲每個數組創建一個內部循環,或者創建一個通用遞歸來迭代所有可能的情況。 – theoden

回答

0

我還以爲你要輸出size_attr[]color_attr[]。 尋找最後的cout<<,那就是轉義字符。

#include <cstdlib> 
#include <iostream> 
#include <string> 
using namespace std; 
int main(int argc, char** argv) { 

    string size_attr[] = {"Extra Small","Small","Medium","Large","Extra Large"}; 
    string size_abv[]={"XS","S","M","L","XL"}; 
    string color_attr[]={"Red","Green","Blue","Black","White"}; 
    string color_abv[]={"RED","GRE","BLU","BLA","WHI"}; 

    //"","""polo-M-GRE""","polo-M-GRE","Products","Unit",0,"","","","Size","Medium",0,0.0,0.0,0.0,"","","","","","" "","","","","","","","","","Colour","TTR",0,0.0,0.0,0.0,"","","","","","" 
    for (int i = 0; i < (sizeof (size_attr)/sizeof (*size_attr)); i++) 
    { 
     for (int y = 0; y <= 4; y++) 
     { 
//   cout <<"\"\",\"\"\"polo-M-RED\"\"\",\"polo-M-RED\",\"Products\",\"Unit\",0,\"\",\"\",\"\",\"Size\",\"Medium\",0,0.0,0.0,0.0,\"\",\"\",\"\",\"\",\"\",\"\" \"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"Colour\",\"Red\",0,0.0,0.0,0.0,\"\",\"\",\"\",\"\",\"\",\"\""<< endl; 
      cout <<"\"\",\"\"\"polo-M-RED\"\"\",\"polo-M-RED\",\"Products\",\"Unit\",0,\"\",\"\",\"\","<<size_attr[i]<<",\"Medium\",0,0.0,0.0,0.0,\"\",\"\",\"\",\"\",\"\",\"\" \"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"Colour\",\""<<color_attr[y]<<"\",0,0.0,0.0,0.0,\"\",\"\",\"\",\"\",\"\",\"\""<<endl; 
     } 
    } 

    //Output escape characters 
    cout<<" \" ' < > , . ~ ! @ # $ %^& * () _ + - = [ ] { } : ; ?/| \\"<<endl; 
    return 0; 
} 

結果:

Printed Screen Outputs - Console