New kid on the block

Pages: 12
Hi my name is Jeremy, I play a lot of Minecraft but have just recently been studying the art of C++ programming. But thereason for this post is I would like some help through this and any help or suggestions would be very much appreciated!
What sort of problems are you having?

(Another Minecraft player? Yay! Part of the only reason I have a little experience in Java is because that's the language Minecraft's programmed in.)

It's not that different, maybe a couple syntactical differences, but the biggest changes are:

C++ is not memory managed. Memory management is an important bit of C++, so that'll be something that'll take a bit of effort.

But C++ has Multiple Inheritance, effectively allowing one class to inherit from two or more base classes! There are a few problems it raises, but there are ways to take care of them.

The other big difference is templates, which are, well, templates from which functions (methods in Java, I think) and classes are instantiated. They're quite a bit like functions that return a class or a function (not literally, though, but they're similar), and the arguments they can take are some of the normal ones, and a new sort of "variable type" (which can only be used in templates), the typename! A typename is basically a variable type or a class.
Last edited on
i am not having trouble i just am new and could use a few pointers. and wtf is a buffer?
First suggestion, take a quick read through this

http://cplusplus.com/forum/beginner/1/
why
its just another forum
Last edited on
plus i have a book that i am reading that tells me all about programming and i know the basics
why
its just another forum


Because it has some forum etiquette that is good to have. If you have specific questions, feel free to ask
what is the buffer ; is it like a sort of way of saying what is on the screen?

also i am not that old so i don't have much of an idea for anything to do like maybe if someone would give me an algorithm for which to base on my programs because i've got nuthin.

Also also is there a way to just type the code on a normal text document and run it on the command prompt application?
Last edited on
If you know the basics then you would know what buffer is as buffer is usually touched on in different respects. I know it was touched on in all of my books when it talked about standard input and output (cin/cout).

Also also is there a way to just type the code on a normal text document and run it on the command prompt application?


That would be more scripting than programming language at that point. Lua, Perl, Python, and Ruby I think are the favorites for scripting.

I play Minecraft once in a while, but I prefer single player to make builds more so than multiplayer.
Last edited on by closed account z6A9GNh0
whenever i can i always try to go on servers with my friends. But mostly i do singleplayer custom maps.

Also so the buffer is the different outputs and inputs shown on screen in the actual program?
Buffer: http://en.wikipedia.org/wiki/Data_buffer

What do you mean by "algorithm"? Do you want someone to tell you what kind of program to code? There are lots of ideas for programming projects floating around the web but I suggest you think of something that YOU are interested in.

If you want a good structured series of code problems to tackle check into Project Euler: http://projecteuler.net/
As a programmer you are the one making the algorithms (unless you are using the wrong term).

http://en.wikipedia.org/wiki/Algorithm

Excerpt:

In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

More precisely, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function.


Last edited on by closed account z6A9GNh0
Hey, welcome to cpp and good look.
I am Dave! Yognaught, and I would be happy to try and help with any problems you face in future (you seem to have enough answers on the buffer)

I am also a beginner like yourself but I am a little further into the core of console programming. My latest project is a passworded app that can en/decrypt the contents of a txt document (however been having a little trouble with multiple lines)

I too am a minecraft player and I mostly play with friends on the tekkit mod and my own private tekkit server! (i have YouTube vids if your bothered, SatsumaBenji / BonzerBenji)

Anyway once again good luck with cpp and id be happy to help with anything if I can!
I started off free learning by making calculators and tried to make them more intricate and complex as I made new ones. I would suggest trying that.

Also a Minecraft player, but I got into C++ before I had ever heard of Minecraft. I like building things with redstone and messing with my friends on their servers.

@SatsumaBenji
How have you been getting the text out of the document? If you take it out with getline(objectName, str); you shouldn't have any issues. Although I can't remember how to save formatting if that's what you want.
thank you all for the support i appreciate it very much!

on another note if you are a minecraft player and would like a new (vanilla) server to play on and mess around and tell your friends about it.

if you would like to talk to me on skype just tell me your info and i will be sure to get to you.

@SatsumaBenji
i like the idea about encrypting and decrypting, do you think i could take a look in order to play around with it and get ideas

@BHXSpector
thanks for the link it helped a lot i now smarter! YAY
Last edited on
@Cantelopeman
I would be happy to share my project with you however i currently do note have my hard-drive with me (will post code shortly) and please not i have made some changes to it.

I used somebodies recomendation of using a charecter pointer and reading the whole file to then edit and output. Unfortunately although this works on multiple lines it does quite often not edit the whole file properly (usually i have to restart the preogram before editing the file again for some reason)

P.S. my skype name should be same as my username for this forum (and also my Minecraft name) SatsumaBenji
Last edited on
@Satsuma
If you are trying to enter the name of the file to encrypt try
1
2
3
4
5
6
string fileName;
getline(cin, fileName);
const char* name = fileName.c_str();
ifstream file;
file.open(name);
. . . 


This allows for infinite possibilities for file names.

For reading the file, you should try
while(!file.eof())

This will continue the loop until you hit the end of the file.

If you want to use the same object for multiple files, then you have to use
file.clear()

This clears the object so that you can use it multiple times without previous file reads interfering with later ones.

I have run into these errors before and have found these methods to work for me. They will probably help a lot in advancing your project.

@GRex2595 no, while(!file.eof()) does not repeat until you hit the end of the file, it repeats until the internal EOF flag belonging to the file ifstream has been set.

This can mean one of several things
1) You get lucky (or unlucky) and everything "appears to work", that the EOF flag is set upon reading the last line of valid data of the file with getline
2) Your loop overflows by-one because getline ends up causing the EOF flag to be set after reading past the end of the last line of valid data (e.g. if you have an extra newline at the end of the file)
3) You get stuck in an infinite loop because something causes the stream to be set to an invalid state part way through reading the file (or maybe it's invalid before you even started?) - this one can easily happen if you read data using the >> operator instead of getline.

What you need to do to read until the end of a file (or until it fails) is put the call to getline as part of the while condition
1
2
3
4
5
std::ifstream file( "myfile.txt" );
std::string str;
while( std::getline( file, str ) )
{
}  
This is a far more reliable method. The eof flag is more useful after you've finished reading data, e.g. in case you need to determine if the stream is still in a good state (if EOF flag is set, then you know it didn't fail partway through due to some error, or due to the file not being opened, etc). Checking it before trying to read data generally isn't helpful


Alternatively, if you're using >> to read from the stream (e.g. if you have a file which you expect to contain only numeric data):
1
2
3
4
5
std::ifstream file( "myfile.txt" );
int n;
while( file >> n )
{
}  
Last edited on
closed account (zb0S216C)
Cantelopeman wrote:
"wtf is a buffer?"

A buffer is a region of memory which is typically used to store some information while that information being transferred from one location to another. It has other uses, but the latter is the most common.

Wazzak
Last edited on
@Bench
I'm just going off of information that I've learned. I usually use EOF to make sure I end my file read on the last line if I don't know the size of the file, and it's always worked for me. My question is, how does the while(getline(file, str)) work if the getline function isn't a bool function?
Pages: 12