What I am trying to do is fetch a filename in my code, but I'm having trouble getting my head around chars and strings. Here's what I have so far:
string fileno(string name){
int arraySize = sizeof(name);
int start = 0;
int end = arraySize - 1;
string number = "";
for(int i = 0; i < arraySize; i++){
if(name[i] == "/"){
start = i;
}else if(name[i] == "."){
end = i;
}
}
for(int i = start; i <= end; i++){
number = number + name[i];
}
return(number);
}
int main(int argc, char *argv[])
{
string filename = fileno(argv[1]);
return 0;
}
The errors I'm getting complain that const char * can't be converted to int. What am I doing wrong?
On a secondary note, is there a reason why taking file input on the main function (the argc, argv stuff) would stop ofstream from working? If so, how can I get around it?

New Topic/Question
Reply



MultiQuote






|