If you don't want to use arrays then you might have to read file multiple times.
int counter = 0;
int sum1=0;
ifstream fin,fin2; //fin and fin2 to read the file each time.
fin.open("myfile.txt"); //opening a file to read it.
while (!fin.eof() ) //reading a file
{
fin>>X;
sum1 = sum1+X; //adding all the numbers in the file
counter++; //counting number of items in the file
}
fin.close()
//Now first calculate mean
int mean=0;
mean = sum1/counter; //calculating the mean
//now calculate sum of squares of difference of each term and mean
int sum2=0;
fin2.open("myfile.txt"); //again opening the file with fin2
while (!fin2.eof() ) //again reading the file
{
fin2>>Y;
sum2 = sum2+ pow(Y-mean,2);
}
fin2.close()
//finally standard deviation
double sd=0;
sd = sqrt(sum2/mean); //calculating standard deviation