So we're supposed to use pointers to allocate memory and addresses of the variable, reading a text file on each line which begins with a char corresponding to integer, double, and string, printing the data and it's location and adding it to a sum or concatenation. Then printing the final sums and concatenation and their addresses. First: Am I using "new" and "delete" in the wrong places? Second: Before I had new and delete I was setting *iPtr = &IntSum, which is wrong, but I couldn't get my program to read the char and properly print the corresponding output (ie, the line where the char is m, doesn't output the error message, and when I only had the if statement with 'i' written it would print all of the text) Third: How do I print the address of the sums and concatenation if they aren't associated with the pointers
while(clab12>>a)
{
if (a=='s') // Note: = assign / == compare
{
string * sPtr = new string; // Note: moved from line 18
clab12>>*sPtr;
cout<<*sPtr<<"\t"<<sPtr<<endl;
strHold = strHold+*sPtr+" ";
delete sPtr;
}
... // Note: Change the other else branches like above
else // Note: you need an else for 'q'
{
cout<<"Data type is not correct"<<endl;
}
}
// Note: move it out of the loop
cout<<"Sum----------Address"<<endl;
cout<<strHold<<"\t"<<&strHold<<endl;
...