So, here’s my code for a simple part of a class:
void ArrayToTextFile::textfiller(string *givenpointer){
cout<< "Recieved array pointer address" << givenpointer << endl;
const char * constantcharversion = path.c_str();
ofstream filler(constantcharversion);
int i = 0;
//string delims = (string)delim;
for(i = 0; i < sizeof(*givenpointer); i++) {
filler << *givenpointer << delim;
givenpointer = givenpointer + 1;
}
filler.close();
}
The pointer points the first element in an array of strings.
delim is a ‘;’
This is my main class:
#include <iostream>
#include "ArrayToTextFile.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
system("color 1A");
cout << "Hello world!" << endl;
string kinch[3] = {"a", "second el", "third"};
ArrayToTextFile newone("C:/haha.txt", ';');
string *pointy = &kinch[0];
newone.textfiller(pointy);
return 0;
}
Whenever the program runs, I can never make it to the return statement. In fact I have to click the exit button on the console window. When I look at the text file created it’s huge:

What is my problem? How can I fix this?
You need to pass in the number of elements in the array.
sizeofwill only give you a size in bytes, which is rarely useful. In order to get the size of an array, you can use(sizeof array)/(sizeof array[0]), but inside the function you only have a pointer, not an array, and this will give you different results.