String and get length problem

Hi everyone,

I'm trying some codes about string arrays and taking array length. But i have some problems. I can't get length of string and can't send to a function.
------------------------
#include<iostream>
#include<cstring>
#include<string>

using namespace std;

void GetLength(string);


std::string Words[]={"table","gun","programming"};

int main()
{
std::string InputWord;
cout<<"Enter a word";
cin >> InputWord;
GetLength(InputWord);//error
}

void GetLength(string str)
{
for(int i = 0; i<3; i++)
{
int Matrix[str.length()][Words[i].length()];//there are errors
}
}

And how can send Matrix to other function? Thanks a lot..
To my knowledge, the string library has some kind of built-in function for getting the length of the string. It would probably look something like this:

1
2
3
4
5
6
7
8
std::string InputWord;
cout<<"Enter a word";
cin >> InputWord;
GetLength(InputWord);//error

//and then to get the length, you would do something like this

InputWord.length();


Also, for your matrix problem, you'll need to have a for loop, or nested (if you have a 2D array) that will read each string.
thanks for reply but it didn't work, i tried it.
Topic archived. No new replies allowed.