嗨我有以下代码,我想通过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;
}
答案 0 :(得分: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;
}
结果: