• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

String Conversion Problem C++

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
So I've decided to make my first windowed application (only previously made command prompt applications). Using C++. I'm making a simple calculator, but I'm having trouble converting a string to a double. The error occurs every time I use the "atof" function on label->Text. I read in my textbook this function should convert a C-string to a double. label1 is the input box for my calculator. Buttons are self explanatory.

Here's what my calculator should look like when finished:

Untitled.jpg


Code:
private: System::Void buttonPlus_Click(System::Object^  sender, System::EventArgs^  e) {
			
			 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '+';
		 }

// Button Minus	
private: System::Void buttonMinus_Click(System::Object^  sender, System::EventArgs^  e) {
	                 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '-';
		 }

// Button Divide	
private: System::Void buttonDivide_Click(System::Object^  sender, System::EventArgs^  e) {
	                 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '/';
		 }

// Button Times
private: System::Void buttonTimes_Click(System::Object^  sender, System::EventArgs^  e) {
	                 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '*';
		 }

Here is the whole code:

Code:
#pragma once
#include <cstdlib> // Needed for string conversion functions
using namespace std;

namespace Calculator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  buttonPlus;
	private: System::Windows::Forms::Button^  buttonMinus;
	private: System::Windows::Forms::Button^  buttonTimes;
	private: System::Windows::Forms::Button^  buttonDivide;
	private: System::Windows::Forms::Button^  buttonEquals;
	private: System::Windows::Forms::Button^  buttonClear;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Button^  button0;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  buttonDecimal;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->buttonPlus = (gcnew System::Windows::Forms::Button());
			this->buttonMinus = (gcnew System::Windows::Forms::Button());
			this->buttonTimes = (gcnew System::Windows::Forms::Button());
			this->buttonDivide = (gcnew System::Windows::Forms::Button());
			this->buttonEquals = (gcnew System::Windows::Forms::Button());
			this->buttonClear = (gcnew System::Windows::Forms::Button());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button0 = (gcnew System::Windows::Forms::Button());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->buttonDecimal = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// buttonPlus
			// 
			this->buttonPlus->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonPlus->Location = System::Drawing::Point(197, 63);
			this->buttonPlus->Name = L"buttonPlus";
			this->buttonPlus->Size = System::Drawing::Size(75, 32);
			this->buttonPlus->TabIndex = 1;
			this->buttonPlus->Text = L"+";
			this->buttonPlus->UseVisualStyleBackColor = true;
			this->buttonPlus->Click += gcnew System::EventHandler(this, &Form1::buttonPlus_Click);
			// 
			// buttonMinus
			// 
			this->buttonMinus->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonMinus->Location = System::Drawing::Point(197, 96);
			this->buttonMinus->Name = L"buttonMinus";
			this->buttonMinus->Size = System::Drawing::Size(75, 32);
			this->buttonMinus->TabIndex = 2;
			this->buttonMinus->Text = L"-";
			this->buttonMinus->UseVisualStyleBackColor = true;
			this->buttonMinus->Click += gcnew System::EventHandler(this, &Form1::buttonMinus_Click);
			// 
			// buttonTimes
			// 
			this->buttonTimes->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonTimes->Location = System::Drawing::Point(197, 166);
			this->buttonTimes->Name = L"buttonTimes";
			this->buttonTimes->Size = System::Drawing::Size(75, 32);
			this->buttonTimes->TabIndex = 3;
			this->buttonTimes->Text = L"*";
			this->buttonTimes->UseVisualStyleBackColor = true;
			this->buttonTimes->Click += gcnew System::EventHandler(this, &Form1::buttonTimes_Click);
			// 
			// buttonDivide
			// 
			this->buttonDivide->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonDivide->Location = System::Drawing::Point(197, 130);
			this->buttonDivide->Name = L"buttonDivide";
			this->buttonDivide->Size = System::Drawing::Size(75, 32);
			this->buttonDivide->TabIndex = 4;
			this->buttonDivide->Text = L"/";
			this->buttonDivide->UseVisualStyleBackColor = true;
			this->buttonDivide->Click += gcnew System::EventHandler(this, &Form1::buttonDivide_Click);
			// 
			// buttonEquals
			// 
			this->buttonEquals->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonEquals->Location = System::Drawing::Point(197, 202);
			this->buttonEquals->Name = L"buttonEquals";
			this->buttonEquals->Size = System::Drawing::Size(75, 45);
			this->buttonEquals->TabIndex = 10;
			this->buttonEquals->Text = L"=";
			this->buttonEquals->UseVisualStyleBackColor = true;
			this->buttonEquals->Click += gcnew System::EventHandler(this, &Form1::buttonEquals_Click);
			// 
			// buttonClear
			// 
			this->buttonClear->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonClear->Location = System::Drawing::Point(134, 201);
			this->buttonClear->Name = L"buttonClear";
			this->buttonClear->Size = System::Drawing::Size(60, 46);
			this->buttonClear->TabIndex = 7;
			this->buttonClear->Text = L"C";
			this->buttonClear->UseVisualStyleBackColor = true;
			this->buttonClear->Click += gcnew System::EventHandler(this, &Form1::buttonClear_Click);
			// 
			// button1
			// 
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button1->Location = System::Drawing::Point(12, 63);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(60, 46);
			this->button1->TabIndex = 11;
			this->button1->Text = L"1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button2->Location = System::Drawing::Point(74, 63);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(60, 46);
			this->button2->TabIndex = 12;
			this->button2->Text = L"2";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button3->Location = System::Drawing::Point(134, 63);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(60, 46);
			this->button3->TabIndex = 13;
			this->button3->Text = L"3";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button5
			// 
			this->button5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button5->Location = System::Drawing::Point(74, 109);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(60, 46);
			this->button5->TabIndex = 14;
			this->button5->Text = L"5";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// button8
			// 
			this->button8->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button8->Location = System::Drawing::Point(74, 155);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(60, 46);
			this->button8->TabIndex = 15;
			this->button8->Text = L"8";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// button4
			// 
			this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button4->Location = System::Drawing::Point(12, 109);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(60, 46);
			this->button4->TabIndex = 16;
			this->button4->Text = L"4";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button7
			// 
			this->button7->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button7->Location = System::Drawing::Point(12, 155);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(60, 46);
			this->button7->TabIndex = 17;
			this->button7->Text = L"7";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// button0
			// 
			this->button0->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button0->Location = System::Drawing::Point(12, 201);
			this->button0->Name = L"button0";
			this->button0->Size = System::Drawing::Size(60, 46);
			this->button0->TabIndex = 18;
			this->button0->Text = L"0";
			this->button0->UseVisualStyleBackColor = true;
			this->button0->Click += gcnew System::EventHandler(this, &Form1::button0_Click);
			// 
			// button6
			// 
			this->button6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button6->Location = System::Drawing::Point(134, 109);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(60, 46);
			this->button6->TabIndex = 19;
			this->button6->Text = L"6";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// button9
			// 
			this->button9->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button9->Location = System::Drawing::Point(134, 155);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(60, 46);
			this->button9->TabIndex = 20;
			this->button9->Text = L"9";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// label1
			// 
			this->label1->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label1->Location = System::Drawing::Point(12, 9);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(260, 45);
			this->label1->TabIndex = 21;
			this->label1->Text = L"0";
			this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
			// 
			// buttonDecimal
			// 
			this->buttonDecimal->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->buttonDecimal->Location = System::Drawing::Point(74, 201);
			this->buttonDecimal->Name = L"buttonDecimal";
			this->buttonDecimal->Size = System::Drawing::Size(60, 46);
			this->buttonDecimal->TabIndex = 22;
			this->buttonDecimal->Text = L".";
			this->buttonDecimal->UseVisualStyleBackColor = true;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->buttonDecimal);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->button9);
			this->Controls->Add(this->button6);
			this->Controls->Add(this->button0);
			this->Controls->Add(this->button7);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->button5);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->buttonClear);
			this->Controls->Add(this->buttonEquals);
			this->Controls->Add(this->buttonDivide);
			this->Controls->Add(this->buttonTimes);
			this->Controls->Add(this->buttonMinus);
			this->Controls->Add(this->buttonPlus);
			this->Location = System::Drawing::Point(12, 13);
			this->Name = L"Form1";
			this->Text = L"Calculator";
			this->ResumeLayout(false);

		}
		
		// Setup variables
		double firstNumber;
		double secondNumber;
		double result;
		char operation;


#pragma endregion

// Button 1
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "1";
			 }
			 else
			 {
				 label1->Text = label1->Text + "1";
			 }
		 }

// Button 2
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "2";
			 }
			 else
			 {
				 label1->Text = label1->Text + "2";
			 }
		 }

// Button 3
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "3";
			 }
			 else
			 {
				 label1->Text = label1->Text + "3";
			 }
		 }

// Button 4
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "4";
			 }
			 else
			 {
				 label1->Text = label1->Text + "4";
			 }
		 }

// Button 5
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "5";
			 }
			 else
			 {
				 label1->Text = label1->Text + "5";
			 }
		 }

// Button 6
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "6";
			 }
			 else
			 {
				 label1->Text = label1->Text + "6";
			 }
		 }

// Button 7
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "7";
			 }
			 else
			 {
				 label1->Text = label1->Text + "7";
			 }
		 }

// Button 8
private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "8";
			 }
			 else
			 {
				 label1->Text = label1->Text + "8";
			 }
		 }

// Button 9
private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text == "0")
			 {
				 label1->Text = "9";
			 }
			 else
			 {
				 label1->Text = label1->Text + "9";
			 }
		 }

// Button 0
private: System::Void button0_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (label1->Text != "0")
			 {
				 label1->Text = label1->Text + "0";
			 }
		 }

// Button Clear
private: System::Void buttonClear_Click(System::Object^  sender, System::EventArgs^  e) {
			 label1->Text = "0";
		 }

/////////////////////////////////////////////////////
// atof function converts a C-string into a double.//
// See page 561 for ohter C-string conversions.    //
/////////////////////////////////////////////////////

// Button Plus		
private: System::Void buttonPlus_Click(System::Object^  sender, System::EventArgs^  e) {
			
			 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '+';		 
		 }

// Button Minus	
private: System::Void buttonMinus_Click(System::Object^  sender, System::EventArgs^  e) {
                 	 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '-';
		 }

// Button Divide	
private: System::Void buttonDivide_Click(System::Object^  sender, System::EventArgs^  e) {
                         firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '/';
		 }

// Button Times
private: System::Void buttonTimes_Click(System::Object^  sender, System::EventArgs^  e) {
	                 firstNumber = atof(label1->Text);
			 label1->Text = "0";
			 operation = '*';
		 }

// Button Equals
private: System::Void buttonEquals_Click(System::Object^  sender, System::EventArgs^  e) {
			 
	                 secondNumber = atof(label1->Text);

			 switch (operation)
			 {
			 case '+': 
				 result = firstNumber + secondNumber;
				 break;
			 case '-':
				 result = firstNumber - secondNumber;
				 break;
			 case '/': 
				 result = firstNumber / secondNumber;
				 break;
			 case '*': 
				 result = firstNumber * secondNumber;
				 break;
			 }
			 
	         label1->Text = result;
		 }
};
}
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
That code is amazing. Not one standard C++ line, and it looks like complete garbage.

Your specific issue comes from the fact that System::Windows::Forms::Label::Text is not a C++ string, but rather some Microsoft class.
Search how to convert that to a normal string.

As to your code........
1) Why are you putting "private:" at every bloody line.
2) Why are you writing some dumb Microsoft typedefs like "System::Void" instead of "void".
3) Why are you using Microsoft namespaces, but then still write the full path to objects... (e.g. "System::Windows::Forms::Form" -> "Form").
4) Why are you not putting repeated similar code in a function (instead of 200 lines, your button registering could be about 20).

But really, just wow. I knew Microsoft code looked ugly from Win32, but this is even worse.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Most of this code was automatically created when I created the form and Dragged and dropped buttons (as you can sort of see in the pictrue). As I said, this is my first windowed application, so I was following a guide. I don't quite understand the code at the moment.

As for the code I wrote, the button events and onward, I was following a youtube tutorial.

Your specific issue comes from the fact that System::Windows::Forms::Label::Text is not a C++ string, but rather some Microsoft class.
Search how to convert that to a normal string.

Ok I'll try to figure this out. Maybe Ill start from scratch judging by your view on the code lol...
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Man I'm getting into a lot of trouble for this aren't I guys? Take it easy, my first windowed program attempt. Haven't finished my beginners C++ textbook, but was eager to start coding a simple program and the tutorial online showed me create the program that way.

I'll put my head back into the books then attempt windowed programs after I'm done I suppose.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
I just hope you have C++/CLI books, and not C++ only, because these two are nothing alike, expect their name :D

I Hope I don't sound silly, but can you elaborate? I've picked up a book on C++. Starting out with C++ by Tony Gaddis. Everything in the book thus far has taught me to do things with console applications. My attempt to create a calculator as a windowed program (is that the right word?) instead of a command console was just for a bit of fun.

I want to get into programming my own indie games. Although I'm not sure exactly how to go about that, at this stage, I thought learning C++ was a good start. Everyone seemed to recommend C++ as the main language for games. After learning the language, I'd invest in a 3d engine and start making games. When I'm confident I can tackle bigger games, I'd put together a team of friends to help with models, sounds, etc.

Are my plans wrong? Have I wasted my time with this book?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
it has nothing to do with your plans or the book itself, but its basically as if you were reading book about C and trying to program C++(the C++/CLI IS different language), but there is nothing wrong in what you do, just the difference you should be aware of
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
no, you created windows form application, that uses C++/CLI, there is exactly 0 pure C++ in there.

If you want to use pure C++, you have to step down from windows form, and use some GUI library to replicate the same effects(wxWidgets, Qt etc)
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
A couple of things.

First of all, this program will give you exactly zero experience in actual game GUIs, you will never use this stuff in a real game code base.

The second thing is that, depending on what your goal is, it might be very much preferable to not learn C++, and move to other things.
This decision mostly relates to whether your goal is to make a game, or to make an engine.
If the former, I would suggest you to use a popular engine like Unity or Unreal Engine 4.

For either game or engine, if you do choose to go your own way, you shouldn't spend your time on this Microsoft nonsense, and instead start spending time with libraries such as SFML that handle window creation, OS events, loading images, audio, etc. (a popular alternative is SDL, though it has a C API, which you might not like).
From there, if you want 3D graphics or any kind of special effects, you will have to learn how to use OpenGL (which SFML/etc. automatically create a context for, relieving you of a lot of pain!), and shaders.

You can of course also use a library like Ogre3D that will handle all of the OpenGL and model loading for you.

The alternative to the above, if you want to stick to Microsoft machines, is to go the DirectX path.
In this case I highly suggest you to use C# an not C++, since it's easier to use, and has all sorts of high-level DirectX wrapper libraries that will handle a lot of mess for you.

Basically, you should really define to yourself what your goal is, and work up from there.

But like I said, if your goal is to make a game, you should probably move directly to a popular game engine.

Also a note on 3D games in general, regardless of how they are made - be prepared to teach yourself some linear algebra, you will need it (mostly vector spaces and transformations, or in other words, vectors and matrices).
 
Status
Not open for further replies.
Top