如何对 n 个字符串执行操作,然后在C++中打印它们
How to perform operations on n number of strings and than print them in C++?
我有一个程序,其中输入了许多 n 个C++字符串。我想用 for 循环输入它们,而不是在新行上打印函数 int operation(字符串 t(的结果?换句话说,我可以在输入字符串(针对每个字符串(后调用函数 operation(( 吗?
#include <iostream>
#include <string>
using namespace std;
int n,counter=0;
int operate (string t)
{
int st=t.find_first_of('E');
for(st; st<t.length(); st++)
{
if(t[st]=='.')
{
continue;
}
else
{
counter++;
}
}
return counter;
}
string k;
int main()
{
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>k;
operate(k);
}
return 0;
}
它返回,但您没有存储返回值。
打印返回值,例如
cout<<operate(k);
否则将返回值分配给另一个变量。返回值存储在另一个变量中。
int temp;
temp = operate(k);
court<<temp;
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- boost::asio如何生成多个协同程序,然后加入它们
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- 在std::thread中,joinable()然后join()线程安全吗
- C++:如何读取分离变量,然后读取向量
- 为什么我的递归函数按降序打印,然后按升序打印?
- 等待整个 omp 块完成,然后再调用第二个函数
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- '{'标记之前的预期类名,然后在预声明时无效使用不完整的类型'class class_name'
- 如何使变量从 x 到 y,然后从 y 返回到 x 并始终重复该过程
- 我有一个数组,我想输入一个范围,然后找到范围内所有偶数的总和?
- 如何正确地推回然后遍历堆中对象的向量?
- 我似乎无法为指针分配一个数组,然后更改数组的内容
- 如何在字符串中找到字符,然后在C++中提取其余的字符串
- 首先按给定顺序打印所有数字,然后使用 Array 打印所有字符和其他符号
- 将加密消息从 php 发送到 C++ 应用程序,然后使用 CryptoPP 进行解密
- 如何为 std::vector 分配内存,然后稍后为某些元素调用构造函数?