-4
私は、いくつかのn個のC++文字列が入力されるプログラムを持っています。私はforループを使ってそれらを入力したいと思いますし、intの演算結果(文字列t)を新しい行に出力するよりも?言い換えれば、文字列を入力した後に関数()を呼び出すことはできますか?n個の文字列に対して演算を実行し、C++でそれらを出力する方法は?
#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;
}
[デバッグ]するまでの時間(https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 – StoryTeller
何を意味するのですか?_何も返さない?関数から戻り値を取ることさえできませんか? – user0042
それが返されます。しかし、あなたは戻り値を保存しませんでした。戻り値を別の変数に代入します。 – Santhosh