-
January 25th, 2013, 08:02 AM
#1
Trying to create a vector using a structure definition as the basis in VC++
I was trying to apply what is here (as someone who writes rarely and has to relearn everything each time):
http://www.daniweb.com/software-deve...ctor-of-struct
I'm using a header file to define the structure:
#ifndef EINSTEIN_H
#define EINSTEIN_H
#include <stdio.h>
#include <vector>
struct SizeAll{
double year;
double R;
SizeAll() { year = 0; R = 0; }
};
int write_to_file(int count, struct SizeAll *data, char const
*fileName)
{
FILE* fp;
fp = fopen(fileName, "w");
if (fp == NULL) return -1;
while (count-- > 0) {
fprintf(fp, "%d,%d\n", data->year, data->R);
//check for errors writing to file
if (ferror(fp)) return -1;
}
fclose(fp);
return 0;
}
#endif
I've loaded the following in the "main.cpp" equivalent. (Not called "main.cpp", but serves the same purpose.)
#include "stdafx.h"
#include <vector>
#include <stdio.h>
#include "Einstein.h"
#include <math.h>
#include "Form1.h"
The code that actually seeks to generate the vector using the structure definition follows:
int counter,year,retval,count;
vector<SizeAll> Universe;
Universe.resize(5);
vector<SizeAll> *heretis;
char const NameFile[]="D:\\Friedout.csv";
heretis=&Universe;
Universe.R = double(366);
Universe.year = double(188);
for ( counter = 15000 ; counter > 99 ; counter-- )
{
Universe.year =double(counter);
Universe.R = double(counter*2);
if (counter==100||counter ==2500||counter==5000||counter==7500||counter==10000||counter==12500||counter==15000)
{
retval=write_to_file(1, heretis, NameFile);
if (retval ==-1)
{
break;
}
}
}
This creates quite a mess. It seems that somehow the "vector" declaration isn't working as the referenced web link seems to suggest that it should. I presume that, as usual, clearing one real error will eliminate the cascade of errors the first real error produces. Can anyone clear this up for me? Why won't VC++ accept the "vector" identifier? Thank you.
The error messages that follow the build attempt are:
Friedman.cpp
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(22): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(80): warning C4067: unexpected tokens following preprocessor directive - expected a newline
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'vector' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2275: 'SizeAll' : illegal use of this type as an expression
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(82): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(83): error C2228: left of '.resize' must have class/struct/union
type is ''unknown-type''
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'vector' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2275: 'SizeAll' : illegal use of this type as an expression
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Einstein.h(9) : see declaration of 'SizeAll'
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(84): error C2065: 'heretis' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'heretis' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(87): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(88): error C2228: left of '.R' must have class/struct/union
type is ''unknown-type''
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(89): error C2228: left of '.year' must have class/struct/union
type is ''unknown-type''
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(92): error C2228: left of '.year' must have class/struct/union
type is ''unknown-type''
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2065: 'Universe' : undeclared identifier
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(93): error C2228: left of '.R' must have class/struct/union
type is ''unknown-type''
d:\documents and settings\xx\my documents\visual studio 2010\projects\friedman\friedman\Form1.h(96): error C2065: 'heretis' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|