Strlen と同じことを行う関数を作成したいのですが、「string subscript out of range」というエラーが表示されます。私はそれを修正しようとしましたが、わかりません。
コードは次のとおりです。
#include "stdafx.h"
#include "stdafx.h"
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int strlen1( string str)
{
int count=0;
int i=0;
while (str[i]!='\0')
{
count++;
i++;
}
return count;
}
int _tmain(int argc, _TCHAR* argv[])
{
string input;
cin >> input;
cout << strlen1(input) << endl;
return 0;
}
ありがとう!