Well you dont need
#include "StdAfx.h"
but that wouldn't make it not compile, what error do you get/
When I tried it without
#include "StdAfx.h"
it wouldn't compile saying I need it. When I included it, it says cout isn't a member of std.
What compiler are you using?
Microsoft Visual C++ 2010 Express Edition
[QUOTE=VeryNiceGuy;26088324]Hey guys, I decided to start learning C++. The basic "Hello, world!" won't compile and I'm wondering why.
[/QUOTE]
Remove line 5 and replace cout by std::cout
I get the same exact error.
[code]
1>c:\documents and settings\Quirk\my documents\visual studio 2010\projects\startingc++\startingc++\startingc++.cpp(9): error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\Quirk\my documents\visual studio 2010\projects\startingc++\startingc++\startingc++.cpp(10): error C2039: 'cout' : is not a member of 'std'
1>c:\documents and settings\Quirk\my documents\visual studio 2010\projects\startingc++\startingc++\startingc++.cpp(10): error C2065: 'cout' : undeclared identifier
[/code]
The program compiles fine for me under gcc.
-snip-
[QUOTE=Matthew0505;26092890]Is it a win32 or CLI project?[/QUOTE]
win32
There should be an option among the lines of Empty Project. Select that, then there should be no source or header file at all.
I posted this on gamedev, but if any of you guys here are pretty good with fmod, I could use some help.
[url]http://gamedev.stackexchange.com/questions/5671/fmod-c-wave-data-of-a-whole-sound[/url]
In short:
I'm using fmod (C++ syntax), and I need to be able to get the wave data of a whole sound. Unfortunately the documentation isn't too understanding, at least for me at this moment.
[QUOTE=ZeekyHBomb;26104103]There should be an option among the lines of Empty Project. Select that, then there should be no source or header file at all.[/QUOTE]When I do the plain 'Empty Project' it compiles fine but says it can't find the executable when I try to debug. Should I use CLR Empty Project?
[B]Edit:[/B]Tried this, works fine.
Bresenham, why must you fail me?
[IMG]http://i55.tinypic.com/vct504.png[/IMG]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Adferdir_verk
{
class Adferdir
{
static void Main(string[] args)
{
string svar = null;
do
{
valmynd();
svar = Console.ReadLine();
switch (svar)
{
case "1":
{
}
break;
default: Console.WriteLine("Rangur innsláttur");
break;
}
} while (svar!="Q".ToLower());
}
public static void valmynd()
{
Console.WriteLine("##### Valmynd #####");
Console.WriteLine("1. Rúmmal kassa");
Console.WriteLine("2. Flatarmál þríhyrnings");
Console.WriteLine("3. Flatarmál hrings");
Console.WriteLine("4. Rúmmál kúlu");
Console.WriteLine("Ýttu á Q/q til að hætta");
Console.WriteLine("##### Valmynd #####");
}
public static int Rummal_kassa(int lengd, int breidd, int hæð)
{
int rummal = 0;
Console.WriteLine("sláðu inn lengd");
lengd=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn hæð");
hæð = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn breidd");
breidd = Convert.ToInt32(Console.ReadLine());
rummal = lengd * breidd * hæð;
return rummal;
}
}
}
how do i put Rummal_kassa to the switch "1"
i get the error No overload for method 'Rummal_kassa' takes 0 arguments
[QUOTE=007;26116865]how do i put Rummal_kassa to the switch "1"
i get the error No overload for method 'Rummal_kassa' takes 0 arguments[/QUOTE]
Change the function to:
[cpp]public static int Rummal_kassa()
{
Console.WriteLine("sláðu inn lengd");
int lengd = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn hæð");
int hæð = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn breidd");
int breidd = Convert.ToInt32(Console.ReadLine());
return lengd * hæð * breidd;
}[/cpp]
Also you have some spelling mistakes in your text. :P
Don't forget you can use the [noparse][code] or [cpp][/noparse] tags.
[QUOTE=yngndrw;26117125]Change the function to:
[cpp]public static int Rummal_kassa()
{
Console.WriteLine("sláðu inn lengd");
int lengd = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn hæð");
int hæð = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("sláðu inn breidd");
int breidd = Convert.ToInt32(Console.ReadLine());
return lengd * hæð * breidd;
}[/cpp]
Also you have some spelling mistakes in your text. :P
Don't forget you can use the [noparse][code] or [cpp][/noparse] tags.[/QUOTE]
thx man got it to work
[QUOTE=VeryNiceGuy;26088324]Hey guys, I decided to start learning C++. The basic "Hello, world!" won't compile and I'm wondering why.
[/QUOTE]
[media]http://www.youtube.com/watch?v=JlcPIjCTxLk&feature=fvsr[/media]
nvm, you fixed it
Just wondering but
this is how i do the grid lines, just wondering if this is the best way to do it?
[cpp]
for(int i = 0 ; i < windowWidth/gridSize ; i++ )
{
Line = sf::Shape::Line(gridSize*i, 0, gridSize*i, windowHeight, 1, sf::Color(2,36,1));
App.Draw(Line);
}
for(int i = 0 ; i < windowHeight/gridSize ; i++ )
{
Line = sf::Shape::Line(0, gridSize*i, windowWidth, gridSize*i, 1, sf::Color(2,36,1));
App.Draw(Line);
}[/cpp]
If you don't have to zoom or don't care about the quality loss, you could use a texture, possibly pre-rendered by the application for optimal adaption to the resolution.
Could someone recommend me a good Matrix (if it also includes vectors then all the better) library that'll work nicely with OpenGL?
I've found a couple but I'd like to know what other people like using
[QUOTE=Chris220;26119465]Could someone recommend me a good Matrix (if it also includes vectors then all the better) library that'll work nicely with OpenGL?
I've found a couple but I'd like to know what other people like using[/QUOTE]
I'm using my own vector and matrix class. Didn't help you tho.
[QUOTE=likesoursugar;26119554]I'm using my own vector and matrix class. Didn't help you tho.[/QUOTE]
Fair enough...
Maybe I should just roll my own
[QUOTE=ZeekyHBomb;26119275]If you don't have to zoom or don't care about the quality loss, you could use a texture, possibly pre-rendered by the application for optimal adaption to the resolution.[/QUOTE]
Textures should actually scale quite nicely, especially if you enable mipmapping.
You could also use a quad with the grid texture being procedurally generated by the pixel shader - That way you have very good batching and perfect scaling.
[QUOTE=Chris220;26119465]Could someone recommend me a good Matrix (if it also includes vectors then all the better) library that'll work nicely with OpenGL?
I've found a couple but I'd like to know what other people like using[/QUOTE]
Does OpenGL not have a built in set of classes for matrices and vectors ? I personally just use the built-in DirectX ones - I used to use a library that one of my University tutors made which was very neat and nice to use, but after a while I got fed up with having to include it and its dependencies into every project especially when DirectX already had a library.
[QUOTE=yngndrw;26120983]
Does OpenGL not have a built in set of classes for matrices and vectors ?[/QUOTE]
Indeed it does not.
edit:
Don't compare DirectX to OpenGL. The closest equivalent would be Direct3D. OpenGL is just a rendering API.
[QUOTE=yngndrw;26120983]Does OpenGL not have a built in set of classes for matrices and vectors ?[/QUOTE]
As jA_cOp said, it's only a rendering api, whereas DirectX contains pretty much half of a game development library, pre-made vector classes and stuff like that – whereas OpenGL just wants input to feed to the GPU.
I'm trying to read the raw byte values from a file, and store them in an unsigned char array
Simple right?
Problem is, visual studio's "immediate window" AND my debug outputs are showing that my array has a load of bytes at the end which aren't in the file, and I'm not sure how they got there
For example:
File contains "hello facepunch what is this madness? I don't get it :<"
Upon running the program, my array contains: "hello facepunch what is this madness? I don't get it :<ýýýý««««««««þîþîþ" (that's it shown in ASCII of course)
Here's my code:
[cpp]std::ifstream stream(filename, std::ios::in | std::ios::binary);
// Couldn't open the file
if(!stream.good())
{
cout << endl << "Failed to open file" << endl
<< "Either the file doesn't exist, or it's in use" << endl
<< "Terminating." << endl;
PromptExit();
return 0;
}
stream.seekg(0, std::ios::end); // Seek to the end of the filestream
unsigned long size = stream.tellg(); // Return the size in bytes
// Move back to the first byte in the file
stream.seekg(0, std::ios::beg);
// Something went wrong!
if(size == -1)
{
cout << "Couldn't determine file size; terminating" << endl;
PromptExit();
return 0;
}
cout << "File is " << size << " bytes" << endl;
cout << "Loading file data into memory..." << endl;
// Now create an array to hold the file data
unsigned char *fbytes = new unsigned char[size];
stream.read(reinterpret_cast<char*>(fbytes), size);
delete[] fbytes;[/cpp]
My "size" variable is showing the correct size (55 bytes), and I've triple-checked that that is definitely the size of the file
Why has my array got these extra bits at the end?
I'm currently working on a RPG forum calculator thingy and something I'd like to be able to do is copy what people post as actions and paste them into the program, then randomly choose one of the posts as what the player should do.
How might I go about doing this?
[QUOTE=Chris220;26122999]I'm trying to read the raw byte values from a file, and store them in an unsigned char array
Simple right?
Problem is, visual studio's "immediate window" AND my debug outputs are showing that my array has a load of bytes at the end which aren't in the file, and I'm not sure how they got there
For example:
File contains "hello facepunch what is this madness? I don't get it :<"
Upon running the program, my array contains: "hello facepunch what is this madness? I don't get it :<ýýýý««««««««þîþîþ" (that's it shown in ASCII of course)
Here's my code:
[cpp]std::ifstream stream(filename, std::ios::in | std::ios::binary);
// Couldn't open the file
if(!stream.good())
{
cout << endl << "Failed to open file" << endl
<< "Either the file doesn't exist, or it's in use" << endl
<< "Terminating." << endl;
PromptExit();
return 0;
}
stream.seekg(0, std::ios::end); // Seek to the end of the filestream
unsigned long size = stream.tellg(); // Return the size in bytes
// Move back to the first byte in the file
stream.seekg(0, std::ios::beg);
// Something went wrong!
if(size == -1)
{
cout << "Couldn't determine file size; terminating" << endl;
PromptExit();
return 0;
}
cout << "File is " << size << " bytes" << endl;
cout << "Loading file data into memory..." << endl;
// Now create an array to hold the file data
unsigned char *fbytes = new unsigned char[size];
stream.read(reinterpret_cast<char*>(fbytes), size);
delete[] fbytes;[/cpp]
My "size" variable is showing the correct size (55 bytes), and I've triple-checked that that is definitely the size of the file
Why has my array got these extra bits at the end?[/QUOTE]
How are you outputting the array?
[QUOTE=ZeekyHBomb;26123233]How are you outputting the array?[/QUOTE]
First way I tried:
[cpp]for(int i = 0; i < size; i++)
{
cout << fbytes[i];
}[/cpp]
Second way (as a confirmation that my for loop wasn't broken) I simply typed "fbytes" into the immediate window and hit enter.
Strange. Try
[cpp]cout << i << ": " << fbytes[i] << '\n';[/cpp]
as for the immediate window (for getting values of variables while debugging I guess?), maybe the debugger is not aware of the size of that array, possibly treating it like a null-terminated string.. dunno; you could test that by null-terminating that array and looking at the value in that window again.
[editline]17th November 2010[/editline]
Also, you're doing this before the delete[], right?
Sorry, you need to Log In to post a reply to this thread.