errors below what am I doing wrong c include include includ
errors below - what am I doing wrong c++
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int heigth = 0; //initialize variables
int width = 0;
const int amount = 3;
struct pixelimage // create structure to hold image
{
int **tempa;
int r,g,b;
int rows, cols;
}image1;// structure type pixelimage
int main()
{
const int amount = 3; //variable r b g
string sentence, filename, mgicnum; //variable to hold comments, magic number and filename
int width, height, maxCol;
ifstream inputFile; //open input and output file
ofstream outputFile;
outputFile.open(\"Alec001.ppm\", ios:: in | ios::out); //file to open in irfan
cout << \"enter a file \" << endl; // user prompt
cin >> filename;
inputFile.open(\"lec001.ppm\");
//image2 = inputfile.open(image2.ppm)
inputFile >> mgicnum;//read in header information
while ((inputFile>>ws).peek() == \'#\') { inputFile.ignore(4096, \'\ \');}
inputFile >> height;
inputFile >> width;
inputFile >> maxCol;
cout << mgicnum ;
cout << height ;
cout << width ;
cout << maxCol<<endl;
outputFile << mgicnum << endl;
outputFile << sentence << endl;
outputFile << height << \" \" << width <<endl;
outputFile << maxCol <<endl;
int totalsize = (height * width * amount); // total size of array
int *tempa;
int i;
tempa = malloc(sizeof(int)* totalsize);// allocate memory so program does not crash **** error here invalid conversion
for (i =0; i < totalsize; i++) {
tempa[i] = 0;
}
free(tempa);
for (int i = 0; i < totalsize; i++){
inputFile >> (tempa.r, tempa.g, tempa.b); **** errors here request for member r in tempa request for member g in temp request for member g in temap
Solution
//modified program
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int heigth = 0; //initialize variables
int width = 0;
const int amount = 3;
struct pixelimage // create structure to hold image
{
int **tempa;
int r,g,b;
int rows, cols;
}image1;// structure type pixelimage
int main()
{
const int amount = 3; //variable r b g
string sentence, filename, mgicnum; //variable to hold comments, magic number and filename
int width, height, maxCol;
ifstream inputFile; //open input and output file
ofstream outputFile;
outputFile.open(\"Alec001.ppm\", ios:: in | ios::out); //file to open in irfan
cout << \"enter a file \" << endl; // user prompt
cin >> filename;
inputFile.open(\"lec001.ppm\");
//image2 = inputfile.open(image2.ppm)
inputFile >> mgicnum;//read in header information
while ((inputFile>>ws).peek() == \'#\') { inputFile.ignore(4096, \'\ \');}
inputFile >> height;
inputFile >> width;
inputFile >> maxCol;
cout << mgicnum ;
cout << height ;
cout << width ;
cout << maxCol<<endl;
outputFile << mgicnum << endl;
outputFile << sentence << endl;
outputFile << height << \" \" << width <<endl;
outputFile << maxCol <<endl;
int totalsize = (height * width * amount); // total size of array
int *tempa;
int i;
//modified
tempa = (int *)malloc(sizeof(int)* totalsize);// allocate memory so program does not crash **** error here invalid conversion
//
for (i =0; i < totalsize; i++) {
tempa[i] = 0;
}
free(tempa);
for (int i = 0; i < totalsize; i++){
inputFile >> (image1.r, image1.g, image1.b);//modified
}
}


