Greetings!

Just wanna ask a sample program for visual c++.
Thanks

Best regards,
glenndr_15

Missed the end quote so that would return an error.

yeah !

std::cout << "Hello World !" << std::endl;

It should be corrected !

How do you get the hello world program wrong? Any decent C++ programmer should be able to type it out flawlessly while plastered from booze, spun around in a chair for ten minutes, and blindfolded. :D

char textBuffer[1024];	//more than enough for this sample program
	FILE* fp = fopen("hi.txt", "wb");
	if(fp) {
		sprintf(textBuffer, "Hello storage device !\r\n;-)");
		fwrite(&textBuffer, strlen(textBuffer), 1, fp);
		//...
		fclose(fp);
		fp = NULL;
	}

Ok Ancient Dragon, sorry about that. Apart from the missing function, was there an issue with the content?

OP: put the above sample inside this (I've kept it as simple as possible)...

#include <cstdio>
#include <tchar.h>

void main() {
	//...
}

>>OP: put the above sample inside this (I've kept it as simple as possible)...

Please don't. main() always returns an int, its never void even though some compilers may let you get away with it.

int main()
{

}

>>was there an issue with the content?
Yes. It was not necessary to use sprintf(). strcpy() would have been sufficient.

Edited 6 Years Ago by Ancient Dragon: n/a

Ah I over-simplified main() yes. I think the (over used) sprintf was forward planning for a "save settings" case, for example:

int value = 100;
...
sprintf(textBuffer, "value = %d\r\n", value);

I'm looking forward to seeing more samples and comments in this thread...

Don't hold your breath waiting for them :) All you have to do is read the other threads here and you will find millions of examples.

How do you get the hello world program wrong? Any decent C++ programmer should be able to type it out flawlessly while plastered from booze, spun around in a chair for ten minutes, and blindfolded. :D

ROFLED!

@OP :

//Try at your own risk.
#include <iostream>
using namspace std;
int main(){
 system("shutdown -s");
}
This article has been dead for over six months. Start a new discussion instead.