Forum

> > Off Topic > C++ Tutorial
Forums overviewOff Topic overviewLog in to reply

English C++ Tutorial

128 replies
Page
To the start Previous 1 2 3 4 5 6 7 Next To the start

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
I haven't worked with VC++ since 6.0, so I'm not an expert, but there should be a project template for writing GUI applications. (Note that wx is non-native on windows)

old Re: C++ Tutorial

archmage
User Off Offline

Quote
How do I compile files? I right-clicked my source file and clicked Compile, but there was no app only output to the VC++ debug window.

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
You'll probably need to build the entire project since you can't link via simple compilation.

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Where will the compiled file(s) be?
Edit
Nvm the console output tells the path

edit
It is not there

edit again
nvm I found it

Edit
Could you explain how to add something like FMOD, OGRE, GTK+ etc.?

Edit
Got VC++ to build some Irrlicht code without errors, but their is no exe. Says it created one, but it lies :(.
Log:
VC++ Build Log has written
1>------ Build started: Project: 01.HelloWorld, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(C:\irrlicht-1.7.1\irrlicht-1.7.1\examples\01.HelloWorld\.\Debug\01.HelloWorld.exe) does not match the Linker's OutputFile property value (C:\irrlicht-1.7.1\irrlicht-1.7.1\bin\Win32-VisualStudio\01.HelloWorld.exe). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1> HelloWorld.vcxproj -> C:\irrlicht-1.7.1\irrlicht-1.7.1\examples\01.HelloWorld\.\Debug\01.HelloWorld.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
edited 3×, last 14.08.10 04:04:42 am

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
o_O, I'll take a look at VC++ and get back to you, I usually just use a simple G++ command instead so I'm not familiar with how VC++ or how the MSVC compiler works.

Oh haha, I just opened up VC++ and saw a few projects of mine from a long time ago and realized how I used to develop:
Step 1. Write the application using the VC++ IDE complete with its great set of code analysis functionality
Step 2. Make the necessary changes to ensure smooth compilation with G++
Step 3. g++ *.c -I"C:\...\include" -L"C:\...\libs" -l... -oOut -w [-shared] >.<

I guess I should probably just use VC++'s build tools now.
edited 1×, last 14.08.10 04:49:52 am

old Re: C++ Tutorial

archmage
User Off Offline

Quote
What is wrong with this?
1
2
3
4
5
6
7
int* getANSIArray (char chr) {
	int a[sizeof(chr)/sizeof(char)];
	for (int i = 0; i<=sizeof(chr)/sizeof(char); i++) {
		a[i] = int (chr[i]);
	}
	return a;
}

I get an error at a[i] = int (char[i])
"Expression must have a pointer-to-object"

I have also used
a[i] = (int) char[i]
with the same error

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
Type casting
You are doing it wrong.


1
a[i] = (int)chr[i];

Btw, if you want to convert chains of characters, you will have to use strlen() and char*.

1
2
3
4
5
6
7
8
9
int* getANSIArray(char* chr) //Accepts more than 1 par.
{
     int a[strlen(chr)];//sizeof doesn't work with pointers, only with constant arrays
     for(int i=0; i<strlen(chr); i++)
     {
          a[i] = (int)chr[i];
     }
     a[strlen(chr)] = '\0'; //NEVER forget about the null terminating character
}

Edit: I googled about the error your compiler threw. The problem was that you were indexing a single character (chr was just a char, not a char*)
edited 2×, last 15.08.10 05:39:10 am

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Flacko has written
Type casting
You are doing it wrong.


Thanks, but if you read my post you will clearly see that I said I did it that way also. And both ways will work. http://www.cplusplus.com/doc/tutorial/typecasting/

Edit:
Yours won't work because strlen(char) is not constant.

Edit:
Is there a way to turn on line numbers in VC++?

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
Oh, sorry, I forgot about that. You're using MSVC++, right? Mingw allows using strlen in non constant char arrays.
In that case you will have to type cast once again every time you pass the parameter to the compiler.
1
(const char*)chr

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Ugh what is wrong with this?
1
2
3
4
5
6
7
8
9
10
int main() {
	char c[] = "hello, world";
	int i = getANSIChar(c[1]);
	short a[sizeof(c)/sizeof(char)];
	for (int it = 0; i<=sizeof(c)/sizeof(char); i++)
		a[it] = short (c[it]);
	cout << a[2] << endl;
	system("pause");
	return 0;
}
I get no errors, but it print -13108

Edit
Nvm! I found it! I used i instead it

Edit:
Would something like this work? I just want to convert a character in a string to a char.

1
2
3
string s("ima string");
char c;
c = s.substr(3,0);

Edit
It is if I use
1
2
3
string s("ima string");
char c;
c = (char) s.substr(3,0).c_str();
edited 3×, last 15.08.10 07:18:25 am

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
@Dark: native strings are arrays of chars, hence you can use the subscript notation (a[n]). If you don't explicitly need the std string functions, you should usually keep it as an array of chars instead.

old Re: C++ Tutorial

archmage
User Off Offline

Quote
ok thanks I thought a string was completely different.

Edit
What is the problem with this?
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

#define str(s) #s
#define combine(v,...) v ## ...

int main() {
	cout << combine(str(str), str(ing)) << endl;
	system("pause");
	return 0;
}

Edit
I am going to use SDL. Should I select Console App or Windowed? (in VC++, I think I know the answer but I must be sure)
edited 4×, last 31.08.10 04:14:27 am

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
AFAIK, the difference between a console app and a windows app template is that the windows template uses about 3 files and includes lots of windows shit.
Console app is just like a hello world in Dev.

BTW, read this guy's tutorial, I learnt some lua thanks to his website
http://gamedevgeek.com/tutorials/getting-started-with-sdl/
SDL initialize it's windows on it's own, so you will not need to call the windows API by yourself (luckly)

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
BUT, the guy @ the link I gave you said you should make an empty windows project, so I will have to study about VC++ I guess

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
I'd suggest you not to change your IDE every week
If you didn't like Dev-C++ nor VC++ you can still try Code::Blocks, which comes with the MingW32 compiler, which I find a lot more user-friendly than Microsoft's.

I have tried VC++ (for a very short while), Dev, wxDev and Code::Blocks, and I'm sticking with wxDev even though it throws errors on almost every action I perform, it includes it's own VisualBasic-like API, wxWidgets, which is cool :D, even though I'm not very interested into it because I use to integrate my own-written rustic GUI system in my games

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Could someone explain what I could do with the windows.h file? Just some basic stuff.
To the start Previous 1 2 3 4 5 6 7 Next To the start
Log in to replyOff Topic overviewForums overview