Hello, I'm new to c++ and I am trying to convert a bruteforce program from Python to c++. Here is what I have so far:

#include <iostream>
#include <string>
using namespace std;

char chars[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
string t;
cout << "Enter a string: " << endl;
cin >> t;
void checkPassword(string password);
void recurse(int width, int position, string baseString);
int main() {
  int maxChars = 13;
  for(int i=0;i<maxChars+1;i++) {
    cout << "checking passwords width [" << i << "]...";
    recurse(i,0,"");
    cout << "\n";
  }
  return 0;
}
void recurse(int width, int position, string baseString) {
  for(int i=0;i<chars.length-1;i++) {
    if (position < width-1) {
      recurse(width, position + 1, baseString+chars[i]);
    }
  }
  checkPassword(baseString+chars[i]);
}
void checkPassword(string password) {
  if (password==t) {
    cout << "\n";
    cout << "match [" << password << "]" << endl;
    system("PAUSE");
    exit(1);
  }
}

But, I'm getting errors when I compile it such as:
bruteforce.cpp:7: syntax error before `<'
bruteforce.cpp:8: syntax error before `>'
bruteforce.cpp: In function `void recurse(int, int, class string)':
bruteforce.cpp:21: request for member `length' in `chars', which is of non-aggre
gate type `char[36]'
bruteforce.cpp:26: warning: name lookup of `i' changed for new ANSI `for' scopin
g
bruteforce.cpp:21: warning: using obsolete binding at `i'

Could someone please help me with these errors?

you are attempting to put code outside a function. Lines 7 and 8 have to be inside a function.

can other functions still access it then if I put it in main()?

This article has been dead for over six months. Start a new discussion instead.