小编NGC*_*543的帖子

Stringstream C++ while 循环

程序在逗号之间找到整数,如“2,33,5”-> 2 33 5。问题是如果我把例如“0,12,4”这样的字符串,它为什么工作。stringstream 不应该将 0 放入 tmp 中,所以循环就像开始时的 while(0) 一样吗?

 vector<int> parseInts(string str) {
 stringstream ss(str);   //getting string 
 vector<int> result;
 char ch;
 int tmp;
 while(ss >> tmp) {      //while(IS IT INTEGER ALREADY OR NOT?)
     result.push_back(tmp);
     ss >> ch;           
}
return result;
Run Code Online (Sandbox Code Playgroud)

c++ loops stringstream zero

4
推荐指数
1
解决办法
6233
查看次数

如何使用循环缩短条件?

我有六个组件数组,我想确保如果用户正在初始化组件的值,他/她将不会给出2个或更多相同的数字.

while (tab[i] == tab[i - 1] || tab[i] == tab[i - 2] || tab[i] == tab[i - 3] || tab[i] == tab[i - 4] || tab[i] == tab[i - 5])
    {
        cout << "Liczby nie moga sie powtarzac! Sproboj jeszcze raz: ";
        cin >> tab[i];
    }
Run Code Online (Sandbox Code Playgroud)

我试着这样做:

while (for (int m = 1; m < 6; ++m)
   {  
     tab[i] == tab[i - m];
   }
Run Code Online (Sandbox Code Playgroud)

但它不起作用:/

c++ arrays loops conditional-statements

2
推荐指数
1
解决办法
113
查看次数

标签 统计

c++ ×2

loops ×2

arrays ×1

conditional-statements ×1

stringstream ×1

zero ×1