-
Parse Error
Probably just some silly error I've overlooked, but even after looking back over the code several times I don't see what's wrong.
Code:
#include <iostream>
#include <string>
using namespace std;
void letters(string test, int plus, int strsize);
int main(){
string test="A string";
int strsize=test.size();
letters(string test, int plus, int strsize);
return 0;
}
void letters(string test, int plus, int strsize){
for(plus=0; plus<strsize; plus++){
cout<<test[plus];
}
}
Error:
Code:
/home/cerin/string.cpp: In function `int main()':
/home/cerin/string.cpp:12: error: parse error before `,' token
-
Well, you are declaring a function inside main, instead of calling it.
Code:
letters(test, plus, strsize);
You also need to define plus
-
Also in your letters function you don't have to pass the 'plus' integer into it, you could initialise it, and the other limit inside the function itself, like so:
Code:
void letters(string test)
{
int strsize = test.size();
for(int i=0; i<strsize; i++) // I replaced your plusses with a i-s
{
cout<<test[i];
}
}
It makes the function's parameters less confusing.