Off-hand, doesn't getline take some parameters? And is it possible that your file uses different line-endings than what getline supports?
std::getline(infile, line);
void readFile()
{
string line;
short loop = 0;
char buffer[256]; //data from text file
int numLines;
ifstream infile;
infile.open("polygon.txt");
// Exit if file opening failed
if (!infile.is_open()){
cerr<<"Failed to open file" <<endl;
exit(1);
}
// Start reading data
while (!infile.eof()){
infile.getline (buffer,100);
cout << buffer << endl;
}
infile.close();
system("PAUSE");
}
Damn I really need help, i've been searching for hours. I'm using C++ and I am trying to read a text file, and store only certain values from that text file into an array so that I can later use them as data values for a polygon.
here's what I have. Something isn't working with the getline() function.
SNIP
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
using namespace std;
void readFile()
{
int number_of_lines = 100;
int linebuffer_maximum = 100;
char buffer[number_of_lines][linebuffer_maximum];
ifstream infile;
infile.open("polygon.txt");
// Exit if file opening failed
if (!infile.is_open()){
cerr<<"Failed to open file" <<endl;
exit(1);
}
int i=0;
// Start reading data
while (i<number_of_lines && !infile.eof()){
infile.getline(buffer[i++],linebuffer_maximum);
}
number_of_lines = i-1;
for(i=0; i<number_of_lines; i++){
cout<<buffer[i]<<endl;
}
infile.close();
}
int main(){
readFile();
}
fstream accountdetails;
accountdetails.open("Account Info.dat", ios::in | ios::out);//opens account file to read and set balance
if (accountdetails.fail())
{
cout << "Error could not open file" <<endl;//failure message
}
for(int i = 0; i < 4; i++)
accountdetails >> input[i];
balance = input[0];
amountD = input[1];
amountP = input[2];
amountW = input[3];
#include <stdio.h>
#define CONSTANT 5
int add_const(int intvar, int constant);
int main(void)
{
int sum, intvar;
printf("Enter a decimal integer:");
scanf("%d", &intvar);
sum = add_const(intvar, CONSTANT);
printf("%d + %d is %d.\n", intvar, CONSTANT, sum);
if(sum < 20)
printf("The number is small.\n");
getchar();
return 0;
}
int add_const(int intvar, int constant)
{
return (intvar + constant);
}
Hello guys
I'm trying to apply as a developer in my current job, but I need to know how to develop video games in C++, is there any good tutorial/course/whatever for that language? I know programming, but I have never developed a videogame.
Thanks!
You do realise this will take months if not years to learn?Hello guys
I'm trying to apply as a developer in my current job, but I need to know how to develop video games in C++, is there any good tutorial/course/whatever for that language? I know programming, but I have never developed a videogame.
Thanks!
I disliked programming until I discovered Haskell.
I'm trying to apply as a developer in my current job, but I need to know how to develop video games in C++, is there any good tutorial/course/whatever for that language? I know programming, but I have never developed a videogame.
You do realise this will take months if not years to learn?
Let me just say that this is a stupid idea. You can't learn video game development by reading some online tutorial over the weekend, it takes ages to learn especially if this should be part of your job. Any recruiter who is even half serious about this will see right through you.
There's just too much stuff you'd have to learn apart from the API(which there are plenty!), maths!, framebuffer, graphics pipeline, rasterizer, vertex format, shaders,...
It's not a weekend plan, I have like a year to learn some basics... so isn't there something that you can help me with?....
Thanks....
It's not a weekend plan, I have like a year to learn some basics... so isn't there something that you can help me with?....
Thanks....
This.Well there is no standard way to develop video games in C++, there are multitude of engines out there and each have different implementation/usage.
What they all have in common however is that they are built on either DirectX or OpenGL which is very low level. It's crucial to have a good knowledge about C++(pointers, memory allocation).
I personally would go with OpenGL as it is cross platform and not bound to any architecture.
If you have it working on a PC you can easily port your code to Android with minimal effort.
But be warned though OpenGL ist not a 3D Engine ready to use, it just provides functionality to talk to the graphics processor and thus it is very low level and therefore very technical so I would suggest a book instead.
If you just want some free C/C++ frameworks:
OgreEngine, irrLicht (3D Engine)
Allegro, SDL (2D Engine)
Source Engine, CryEngine
In C, does scanf() always leave a trailing newline? I used getchar() at the end of my program to pause it before it terminates, but I think scanf is giving me problems. FYI, I run my programs on the console but I still want the programs to pause before they terminate if run on an IDE or as an .exe file. Here's a small program I made.
Well there is no standard way to develop video games in C++, there are multitude of engines out there and each have different implementation/usage.
What they all have in common however is that they are built on either DirectX or OpenGL which is very low level. It's crucial to have a good knowledge about C++(pointers, memory allocation).
I personally would go with OpenGL as it is cross platform and not bound to any architecture.
If you have it working on a PC you can easily port your code to Android with minimal effort.
But be warned though OpenGL ist not a 3D Engine ready to use, it just provides functionality to talk to the graphics processor and thus it is very low level and therefore very technical so I would suggest a book instead.
If you just want some free C/C++ frameworks:
OgreEngine, irrLicht (3D Engine)
Allegro, SDL (2D Engine)
Source Engine, CryEngine
Well there is no standard way to develop video games in C++, there are multitude of engines out there and each have different implementation/usage.
What they all have in common however is that they are built on either DirectX or OpenGL which is very low level. It's crucial to have a good knowledge about C++(pointers, memory allocation).
I personally would go with OpenGL as it is cross platform and not bound to any architecture.
If you have it working on a PC you can easily port your code to Android with minimal effort.
But be warned though OpenGL ist not a 3D Engine ready to use, it just provides functionality to talk to the graphics processor and thus it is very low level and therefore very technical so I would suggest a book instead.
If you just want some free C/C++ frameworks:
OgreEngine, irrLicht (3D Engine)
Allegro, SDL (2D Engine)
Source Engine, CryEngine
Posted this in the Indie Game Development thread too.
----
So GAF, I have a problem.
So I'm starting from scratch, again. What are some good resources? I'd prefer an e-book so I can read it on my iPad when I'm away from my desk or at school. Should I start with C++ again or attempt something else like Java? I'm used to looking at a wall of code, since I never ever used Dreamweaver in WSD, I always hard coded my websites in Notepad++.
Can't wait to see what Gaf recommends! Thanks in advance.
Using scanf() is an extraordinarily bad idea. It's basically a security hole waiting to happen.
i am a comp sci major, and have only taken an intro to c++ class. let's just say that i am not the best at programming. i understand what different lines of code do and what not, but when given a task like make a program that counts characters in a line, i sorta freeze up until someone calmly tells me its so simple all you gotta do is read the file in, there is a library for reading characters in, etc. this upcoming semester i have an object oriented class, and i'm wondering if this will make things easier for me, or even harder. is there anything i should read over during the next month to get myself back in the programming spirit?
i am a comp sci major, and have only taken an intro to c++ class. let's just say that i am not the best at programming. i understand what different lines of code do and what not, but when given a task like make a program that counts characters in a line, i sorta freeze up until someone calmly tells me its so simple all you gotta do is read the file in, there is a library for reading characters in, etc. this upcoming semester i have an object oriented class, and i'm wondering if this will make things easier for me, or even harder. is there anything i should read over during the next month to get myself back in the programming spirit?
I'll have a go at a family Tree, but yes you are right, design is a really big part of Programming.Some easy, fun projects if you want to do OOP:
— Cash dispenser
— Family tree
— Theater ticket reservation
A general approach to understanding how to solve a problem with programming:
— Dissect the problem so that you have all necessary operations in a list
— Implement the data structures
— Implement the operations
— Gather the data
— Execute
— Refine
Here's an example with the cash dispenser:
— A person has an account
— An account has a PIN for identification purposes
— An account has money on it
— The dispenser has an amount of cash stored
— Dispensing money reduces money on an account
— Dispensing money reduces money in the cash storage
— A person cannot dispense more money than is on his account
— A person cannot dispense more money than is left in the dispenser's cash storage
— A person might have multiple accounts because why not
— A person can put money into an account
— Putting money into an account also increases the dispenser's amount of stored cash
— A person can change the PIN for an account (provide old PIN, provide new PIN, confirm new PIN)
And so forth. As you see, splitting it up into atoms makes it just a bunch of very easy programming tasks. That's why experienced programmers say that design is a bigger deal than implementation.
It's hard to say if it'll make things easier or harder. Most of the time, the complexity increases, the number of lines of code increases, but novice programmers have an easier time being productive.
No idea on the reading question. What exactly do you want to explore? OOP in C++? OOP in general? C++ basics?
Also, programming yourself makes for more efficient learning.
probably basics. i want to find something that gives projects to make and then you can see if you do it properly.
i'm at a very beginner level fwiw
Some easy, fun projects if you want to do OOP:
Cash dispenser
Family tree
Theater ticket reservation
A general approach to understanding how to solve a problem with programming:
Dissect the problem so that you have all necessary operations in a list
Implement the data structures
Implement the operations
Gather the data
Execute
Refine
Here's an example with the cash dispenser:
A person has an account
An account has a PIN for identification purposes
An account has money on it
The dispenser has an amount of cash stored
Dispensing money reduces money on an account
Dispensing money reduces money in the cash storage
A person cannot dispense more money than is on his account
A person cannot dispense more money than is left in the dispenser's cash storage
A person might have multiple accounts because why not
A person can put money into an account
Putting money into an account also increases the dispenser's amount of stored cash
A person can change the PIN for an account (provide old PIN, provide new PIN, confirm new PIN)
And so forth. As you see, splitting it up into atoms makes it just a bunch of very easy programming tasks. That's why experienced programmers say that design is a bigger deal than implementation.
probably basics. i want to find something that gives projects to make and then you can see if you do it properly.
i'm at a very beginner level fwiw
Everyone who has to deal with PHP should read through the Fractal of Bad Design rant to fully understand what a minefield of hassles it can be.A note: I hate PHP. It's basically Java, but without declaring variables to be of a type, which just makes things annoying. For example, look at PHP's "find substring in string" function, which can return 0 to say it's at position 0, or false to say it isn't in the string at all. This will cause headaches when testing for equality.
Though it also doesn't have types, I do like Python. It's different with Python, for some reason. Somehow, it's just easier...
Everyone who has to deal with PHP should read through the Fractal of Bad Design rant to fully understand what a minefield of hassles it can be.
document for PHP function intval() said:intval($var, $base)
Get the integer value of a variable
Returns:
int The integer value of var on success, or 0 on failure. Empty arrays and objects return 0, non-empty arrays and objects return 1.
the perfect world said:Returns:
int|boolean The integer value of var on success, or false on failure. Empty arrays and objects return false, non-empty arrays and objects return true.
I will give it a read later. I've heard a lot of complaints about PHP.Everyone who has to deal with PHP should read through the Fractal of Bad Design rant to fully understand what a minefield of hassles it can be.
![]()
Buy this book. I've learned everything I know so far from it, and I started from absolutely no programming experience. Tons of great examples, and very thorough explanations so you're never left to question why something happens like it does. It's also full of review questions and practical exercises to try on your own.
Just a nit here: Python does have types - every object from the lowliest integer to a custom class instance knows its type; what it doesn't have is static (ie. in-code) type declarations for variables. It also rarely allows you to play loose and fast with odd combinations of types like some other languages ;-)Though it also doesn't have types, I do like Python.
So basically, configuration. Anyone have any tips as to what I may be doing wrong in the configuration to make my new server perform so poorly compared to the 5+ year old machine?
They said the execution plans are the same.Definitely sounds like a configuration error and my guess is it's in the big change in RAM. I'd say play around with the config with respect to the max memory usage, maybe pull it down to 24GB.
Also, you can use the query execution plan to analyze how the query is being executed -- it might have changed in reaction to the differing hardware. If it's possible to do a cross-analysis of plans between the old server and new server, you could see the differences and possibly find the issue. http://www.sql-server-performance.com/2006/query-execution-plan-analysis/
would this or Accelerated C++ be better to learn from a beginner's stand point? I like that I can get this one on Kindle but I don't mind ordering the actual book for Accelerated if it is better.
In C, how exactly do you assign a word to a string in a struct? My professor taught how to let the user do it, but not how to hard code it.
Code:example.name[10]="John";
Something like this is what I assumed to be correct, but apparently not.