无法在循环中的if statement结束时增加
Unable to increment at the end of an if-statement in the for-loop
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int main ()
{
//Declaring variables:
int numberoftestcase=0;
string words;
vector<string> holder;
vector<char> character;
int counter=0;
//Allow user inputs a number to declare the size of the vector holder
cin >> numberoftestcase;
//Allow user to input words;
for(int i=0;i<numberoftestcase;i++)
{
cin >> words;
holder.push_back(words);
}
for(int position=0;position<holder[counter].length();position++)
{
if(position<holder[counter].length())
{
character.push_back(holder[counter].at(position));
cout << character[position] << endl;
}
else
{
counter++;
}
}
}
我想提出一个能够
的程序输入一个要声明测试用例的数字。就像输入4一样,这意味着有4个测试用例可以输入(完成)
它可以将字符串分为字符并存储在向量中。(部分完成)
目标2存在问题(请参阅第二循环)。我发现我的程序无法增加计数器。也就是说,一旦持有人[0]完成,它就会离开for循环和结束程序。它不会交给持有人[1],持有人[2]等。
为什么会这样解决问题?
谢谢
您需要两个嵌套的for
循环。一个通过持有者中的单词迭代,一个单词中的字符迭代。我会写为:
for (const auto& word: holder)
{
for (const auto ch: word)
{
character.push_back(ch);
cout << character.back();
}
}
相关文章:
- 为什么在这个代码结束循环中没有得到结束
- 试图对缓存进行跨步测试,但程序并没有结束
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- 为什么擦除方法会影响结束方法
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 删除映射和分割错误中的一个过去结束元素
- 如何使用 SFML 在贪吃蛇游戏中定义游戏结束?
- 为什么我的两个 cin 语句没有在程序结束时运行?
- 在函数结束后使用指向变量的指针是否安全?
- ANTLR GOTO statement
- C ++尝试并捕获未结束的程序
- 为什么我的程序在输入某个形状的面积的测量值后没有结束?
- 取消引用结束指针到数组类型的一个
- 如何在 c++ 中确定一条指令(以字节为单位)在哪里结束,另一条指令从哪里开始?
- 结束另一个线程中使用的对象的生存期
- 全局向量导致 C++ 程序结束时出现段错误
- std::bind c++ in if statement
- 程序显示以退出代码 0; 结束
- 如何显示函数开始、结束行和函数体?
- 无法在循环中的if statement结束时增加