|
this is my all source code, i combined together, it can run smoothly, but i seperated, the problem is like above.
#include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <cstdlib>
using std::rand;
using std::srand;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
#include <ctime>
using std::time;
class Centroids
{
public:
void printArray(double a[3][4] )
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << " ";
cout << endl;
}
}
private:
double a[3][4];
};
int main()
{
Centroids matrix;
int number = 1;
for (int number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4) << number << endl;
matrix.printArray(a);
cout << endl;
}
number = number + 1;
return 0;
}
the following is what i seperated code above, can you help me to check? what is problem?
header file:
include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
class Centroids
{
public:
void printArray(double a[3][4] )
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << " ";
cout << endl;
}
}
private:
double a[3][4];
};
cpp code:
#include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <cstdlib>
using std::rand;
using std::srand;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
#include <ctime>
using std::time;
#include "Centroids.h"
int main()
{
Centroids matrix;
int number = 1;
for (int number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4) << number << endl;
matrix.printArray(a);
cout << endl;
}
number = number + 1;
return 0;
}
thanks a lot
Li Zhiyuan
5/10/2006
|
|
|
|
|
yes, actually i did like this already, centroids just is a class in my header file... i installed vc++ 2005 in D driver, but my project in C driver..so i added a direcotry included my project in C driver...but the problem is still like this.
the following is combined code:
#include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <cstdlib>
using std::rand;
using std::srand;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
#include <ctime>
using std::time;
class Centroids
{
public:
void printArray(double a[3][4] )
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << " ";
cout << endl;
}
}
private:
double a[3][4];
};
int main()
{
Centroids matrix;
int number = 1;
for (int number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4) << number << endl;
matrix.printArray(a);
cout << endl;
}
number = number + 1;
return 0;
}
the following is seperate code:
header file:
include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
class Centroids
{
public:
void printArray(double a[3][4] )
{
for (int i = 0; i <3; 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3)<< setprecision(6) << setiosflags(ios::fixed|ios::showpoint)<< a[i][j] <<; " ";
cout <<; endl;
}
}
private:
double a[3][4];
};
cpp code:
#include <iostream>
using std::endl;
using std::cin;
using std::cout;
#include <cstdlib>
using std::rand;
using std::srand;
#include <iomanip>
using std::setw;
using std::setprecision;
using std::ios;
using std::fixed;
using std::showpoint;
using std::setiosflags;
#include <ctime>
using std::time;
#include "Centroids.h"
int main()
{
Centroids matrix;
int number = 1;
for (int number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4)<< number << endl;
matrix.printArray(a);
cout << endl;
}
number = number + 1;
return 0;
}
Li Zhiyuan
5/10/2006
|
|
|
|
|
What you have here is a big ol' mess. Why have you duplicated the code in both the .h and .cpp files? Put the class declaration in the .h file like:
class Centroids
{
public:
void printArray( double a[3][4] );
}; Then put its definition in the .cpp file like:
#include "centroids.h"
void Centroids::printArray( double a[3][4] )
{
using namespace std;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed | ios::showpoint) << a[i][j] << " ";
cout << endl;
}
} li zhiyuan wrote: int number = 1;
for (int number = 1;
Why do you have number declared twice?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Why do you have number defined twice?
He has the Visual Studio Dumb Edition C++ Compiler.
Thank you for pointing out code mess. I overlooked his code, focusing my attempts to help him to properly set the environment.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
did u find any problem in my code? after i seperated these code, it has a problem after combilation, the problem is like previous one thati showed you in last session.
thanks
Li Zhiyuan
6/01/2008
|
|
|
|
|
Hi Friends
I Am new to this site
i got one problem regarding playback of mpeg compressed files
iam using windows mfc for this
iam receiving the file from the board via tcp protocol and iam storing in the hard disk and then calling decompression function like this
Decompression("filename.M4V");
HERE I WANT DIRECTLY WITHOUT STORING IN THE HARD DISK
IF WE WON'T GIVE EXTENSION TO FILE(LIKE .M4V,.MP4 ETC)IT IS NOT WORKING AT THE FUNCTION guess_format OF AV LIBRARY.
THE DETAILS OF THIS guess_format FUNCTION I DON'T KNOW
while i am storing the file (around 2 mb) in the buffer and calling decompression it is not working.but if you take from hard disk it is working....
pls help me
here m providing the code for reference
int Decompression(char *inputfile)
{
const char *filename;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *video_st;
double video_pts;
unsigned int i = 0;
AVFormatContext *pFormatCtx;
int videoStream = 0;
AVCodecContext *pCodecCtx;
AVFrame *pFrame;
AVCodec *pCodec;
AVPacket packet;
int frameFinished;
const char *filenamei;
AVOutputFormat *fmt1;
// initialize libavcodec, and register all codecs and formats */
av_register_all();
filename = "Girish1.YUV";
filenamei = inputfile;
// auto detect the output format from the name. default is mpeg. */
fmt = guess_format(NULL, filename, NULL);
if (!fmt)
{
printf("Could not deduce output format from file extension: using MPEG.\n");
fmt = guess_format("mpeg", NULL, NULL);
}
if (!fmt)
{
fprintf(stderr, "Could not find suitable output format\n");
exit(1);
}
fmt1 = guess_format(NULL, filenamei, NULL);
if (!fmt1)
{
printf("Could not deduce input format from file extension: using MPEG.\n");
fmt1 = guess_format("mpeg", NULL, NULL);
}
if (!fmt1)
{
fprintf(stderr, "Could not find suitable input format\n");
exit(1);
}
// Open video file input
if(av_open_input_file(&pFormatCtx, filenamei, NULL, 10000, NULL)!=0)
{
printf("Couldn't open input file\n");
return NULL; // Couldn't open file
}
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
{
printf("Couldn't find stream information\n");
return NULL; // Couldn't open file
} // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, filenamei, false);
// Find the first video stream
videoStream=-1;
for(i=0; i < (pFormatCtx->nb_streams); i++)
if(pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO)
{
videoStream=i;
break;
}
if(videoStream==-1)
{
printf("Didn't find a video stream\n");
return NULL; // Didn't find a video stream
}
// Get a pointer to the codec context for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
pCodecCtx->width = RESW;
pCodecCtx->height =RESH;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
printf("Codec not found\n");
return NULL; // Codec not found
}
// bitstreams where frame boundaries can fall in the middle of packets
/* if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
{
pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
}*/
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0)
{
printf("Could not open codec\n");
return NULL; // Could not open codec
}
// Allocate video frame
/*pFrame = alloc_picture(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
if (!pFrame)
{
fprintf(stderr, "Could not allocate picture\n");
exit(1);
}*/
// allocate the output format context */
oc = av_alloc_format_context();
if (!oc)
{
fprintf(stderr, "Memory error\n");
exit(1);
}
oc->oformat = fmt;
_snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
// add the video streams using the default format codecs and initialize the codecs
video_st = NULL;
if (fmt->video_codec != CODEC_ID_NONE)
{
video_st = add_video_stream(oc, fmt->video_codec);
}
// set the output parameters
if (av_set_parameters(oc, NULL) < 0)
{
fprintf(stderr, "Invalid output format parameters\n");
exit(1);
}
dump_format(oc, 0, filename, 1);
// now that all the parameters are set, we can open the video codecs and allocate the necessary encode buffers
if (video_st)
{
if(!(open_video(oc, video_st)))
{
printf("\nfailed to open videostream for output");
exit(1);
}
}
// open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE))
{
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0)
{
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
}
// write the stream header, if any
if((av_write_header(oc)) != 0)
{
printf("\nfailed to write the header");
}
for(;;k++)
{
// compute current video time
if (video_st)
{
video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
}
else
{
video_pts = 0.0;
}
pFrame = alloc_picture(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
if (!pFrame)
{
fprintf(stderr, "Could not allocate picture\n");
exit(1);
}
// write interleaved video frames */
if(av_read_frame(pFormatCtx, &packet)>=0)
{
if(packet.stream_index==videoStream)
{
// Decode video frame
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
video_outbuf_size1 = 2000000; //by me
video_outbuf1 = (unsigned char *) av_malloc(video_outbuf_size1);
if(not_init == false)
{
not_init = true;
InitConvertTable();
}
// ConvertYUVtoYUV(320,240,(unsigned int*)pFrame,(unsigned int*)pFrame);
ConvertYUV2RGB((unsigned char*)pFrame->data[0],(unsigned char*)pFrame->data[1],(unsigned char*)pFrame->data[2],video_outbuf1,RESW,RESH);
PostMessage(g_hWnd,ON_RENDER,(unsigned long)video_outbuf1, NULL);
//Sleep(100);
// Did we get a video frame?
if(frameFinished)
{
if(!(write_video_frame(oc, video_st,pFrame,i)))
{
printf("\nfailed to write the video frame");
exit(1);
}
av_free_packet(&packet);
av_free(pFrame);
}
}
}
else
break;
}
//av_free_packet(&packet);
//av_free(pFrame);
// close each codec */
if (video_st)
{
close_video(oc, video_st);
}
// write the trailer, if any */
if((av_write_trailer(oc)) != 0)
{
printf("\nfailed to write the trailer");
}
// free the streams */
for(i = 0; i < oc->nb_streams; i++)
{
av_freep(&oc->streams[i]->codec);
av_freep(&oc->streams[i]);
}
if (!(fmt->flags & AVFMT_NOFILE))
{
// close the output file */
url_fclose(&oc->pb);
}
// free the stream */
av_free(oc);
av_free(video_outbuf1);
// Close the codec
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
//free(p);
return 0;
}
Girish
Girish
|
|
|
|
|
In excel you can convert a date of 1/4/2008 to 39451 by formating a the cell to numeric.
Not sure how excel does this but would like to do the same thing in my VB.Net program.
Has anyone come across this? ANy Idea's?
Regards
|
|
|
|
|
If you have a look at Excel documentation (date serial numbers) , then a rough procedure maybe
Dim i As Long
Dim dt0 As DateTime, dt1 As DateTime
dt1 = New DateTime(2008, 1, 4)
dt0 = New DateTime(1900, 1, 1)
i = (dt1 - dt0).Days + 2
Please note, this doesn't return decimal numbers on fraction of days (as Excel does).
BTW try also to ask the VB/VB.NET forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Hi,
I created a VB activex dll.In vc++6 i use this DLL in my application path. I used classwizard Automation tab,Import class From Type library,chosen the path of DLL.It worked fine.
IF i change the application to someother path, the DLL did not work.
How to make my application to refer the DLL in the application path?
Manohar
|
|
|
|
|
dear all
the following is what i did, but it is smooth to compile, but after i seperate this code to two, one is header file, the other is cpp....output showed me:
fatal error C1083: Cannot open include file: 'Centroids.h': No such file or directory
so what happened? the seperate code is in second phase.
class Centroids
{
public:
void printArray(double a[3][4] )
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << " ";
cout << endl;
}
}
private:
double a[3][4];
};
int main()
{
Centroids matrix;
int number = 1;
for (int number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4) << number << endl;
matrix.printArray(a);
cout << endl;
}
number = number + 1;
return 0;
}
the following is seperate code:
cpp
void Centroids::oneCentroid(double a[3][4])
{
for (double i = 0; i < 3; i++)
{
for (double j = 0; j < 4; j++)
cout << setw(3) << setprecision(6) << setiosflags(ios::fixed|iso::showpoint) << a[i][j] << " ";
cout << endl;
}
}
int main()
{
Centroids matrix;
int number = 1;
for (number = 1; number <=10; number++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout << setw(4) << number << endl;
matrix.oneCentroid(a);
cout << endl;
}
number = number + 1;
return 0;
}
header file
class Centroids
{
public:
void oneCentroid(double [3][4]);
private:
double a[3][4];
};
thanks a lot
Li Zhiyuan
5/01/2008
|
|
|
|
|
How did you include you header (.h ) file inside the source (.cpp ) one?
Should be via
#include "Centroids.h"
Did you put the header file inside the project source folder?
Did you add the header file to the project?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
yes, i added the #include "Centroids.h" in cpp file, the Centroids.h is a class in header file...
i combined together header file and cpp file, it can compile smoothly, after i seperated, output showed me:
fatal error C1083: Cannot open include file: 'Centroids.h': No such file or directory
i dun know how to set this include path.
thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
Are the two files inside the same folder? If they are not then you must provide a path:
#include "..\..\Centroids.h".
Hope this helps..
|
|
|
|
|
|
Have you seen this article. It's about ISensNetwork , but the steps are identical.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thank you very much for reply.
Now I got the right point.
I have seen this article before posting this thread but as explained in this article it is about ATL COM Application and also in that they have used ATL Simple Object and also Implement Interface.
I tried to include ATL Object in my project but it does allow ATL support to my Application because my application in simple Empty project( I hope ATL object Allows only to MFC PRoject And full ATL support project).SO, now how can I use this Interface into my project.
Is there any other alternative to use SENS And Event System??
Thanks.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
Hi
In my VC 6.0 application , i get local host name , but can't get local ip address. Give me suggestion or code to get local ip address .Below given the code that retrieve the host name.
#include "winsock2.h"
void Sampleappl::GetLocalIpaddress()
{ WSADATA ws;
int recws=WSAStartup(MAKEWORD(2,2),&ws);
if(recws!=NOERROR)
{
MessageBox(NULL,"WSAStartUp Error","ERROR",MB_OK);
return 0;
}
char ipadd[15];
gethostname(ipadd,sizeof(ipadd));
MessageBox(NULL,ipadd,"Local ip address",MB_OK);
return;
}
regards
shakumar
shakumar
|
|
|
|
|
After calling gethostname() , call gethostbyname() to get the IP address.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Does anyone know how I can upgrade dbghelp.dll?
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Deploy
|
|
|
|
|
I've found out that it seems one cannot replace or upgrade the dbghelp.dll that comes installed with the system. If anyone knows otherwise, please let me know!
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Deploy
|
|
|
|
|
I am attempting to find how many rows of text will print per page from a rich edit control in a dialog box. Is there a method for finding the actual height of a text line? Neither the LOGFONT nor the CHARFORMAT nor the TEXTMETRIC structures provide this info accurately.
Doug C
|
|
|
|
|
|
Since rich edit text can have different formatting, the number of
lines per page can vary.
The only reliable way I know is to format the text for the device it
will be printed on, then calculate how many rows.
With a combination of some of the code here[^] and the EM_EXLINEFROMCHAR
message, you should be able to calculate the number of lines per page.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
A moved rectangle how does secure to the const size of itself. Forexample CRect(10,10); It must secure to these sizes when it go move forward. Please help with MFC.
Bitte tun Sie mir nicht antworten, wenn Sie nicht wissen, die Ursache des Problems wirklich oder nur als Antwort. Was ist das? Dies ist das Buch sitzen.
|
|
|
|
|