466 Posted Topics

Member Avatar for n0de

you should probably use [icode]isdigit()[/icode] instead, to decide if doing [icode]atoi()[/icode] is worthwhile. More about these kinds of things [URL="http://www.cplusplus.com/reference/clibrary/cctype/"]here[/URL]

Member Avatar for MeduZaPaT
0
715
Member Avatar for aFg3

[QUOTE=aFg3;1676340][CODE]#include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() { //char sum = 0; char x; ifstream inFile("1.txt"); if (!inFile) { cout << "Unable to open file"; exit(1); } while (x != '\n') { while (inFile >> x) { cout<<"x = "<<x<<endl; } } inFile.close(); getchar(); return 0; …

Member Avatar for Narue
0
192
Member Avatar for flynismo

Given your restrictions, I'd go with Python. If you don't care too much about getting the absolute highest performance, then Python will allow you more flexibility and (contrary to one of the points you make*) portability. If you identify some parts of your Python script that are really slowing you …

Member Avatar for rubberman
0
201
Member Avatar for cypherscouter13

You can't do this: [icode]string SetName(char setName) {Name = setName; }[/icode] You're trying to set a [icode]std::string[/icode] equal to a [icode]char[/icode], which you can't do. You should try: [icode]string SetName(const string& setName) {Name = setName; }[/icode]

Member Avatar for cypherscouter13
0
164
Member Avatar for nuclear

Your algorithm is not going to do what you want it to because you're updating the cells as you check whether they should be alive or dead in the next iteration. To get the effect that you want, you have to make copy of the grid with the updated cell …

Member Avatar for nuclear
0
702
Member Avatar for l0v3csci

Assuming you have some function [icode]IsOccupied[/icode] that returns true if the cell is occupied and the array of cells is stored in a 2D array, [icode]N[/icode], then you could do something like: [code] int neighbours = 0; for( int i = row - 1; i <= row + 1; ++i …

Member Avatar for Fbody
0
8K
Member Avatar for jesz

Sure, what do you have so far? In general, you won't get much help without showing that you've already put some effort in yourself.

Member Avatar for Moschops
0
115
Member Avatar for mukulbudania

Using [icode]std::cout[/icode] you can use the features in [icode]<iomanip>[/icode] for this. See [URL="http://www.cplusplus.com/reference/iostream/manipulators/"]here[/URL]. Or, you can try with [icode]printf()[/icode]. An alternative is to separate everything by tabs/spaces/commas and carriage returns and then output to file and open it in your favourite spreadsheet application.

Member Avatar for ravenous
0
112
Member Avatar for skylinedrifter

Er, I think you're just calculating the standard deviation with the wrong formula. Your original post says that: StdDev = sqrt(X1+X2+X3+X4)/3, which is not correct. To get the stdDev, you need to calculate the mean, with: mean = (X1 + x2 + X3 + X4)/4 and then use that to …

Member Avatar for ravenous
0
1K
Member Avatar for Kron

[QUOTE=Kron;1655753]I'm about to start the 2nd attempt at the program, I'll post the code here when im done, although I'm probably gonna be horribly wrong but will try.[/QUOTE] It might be a start to post your first attempt. If your having problems getting the details right, try missing them out. …

Member Avatar for Narue
0
239
Member Avatar for Zssffssz

In Linux, it's all about GCC. If you're using KDE (which you are if you have Kubuntu) then KDevelop is a pretty comprehensive development environment that uses GCC to compile. If you just get KDevelop from the package manager then it will sort out getting the compiler and all that …

Member Avatar for limaulime
0
228
Member Avatar for dospy

They're roughly equivalent, although the second way has the advantage that the loop will look the same for many types of STL container, some of which don't have [icode]operator[][/icode]. Depending on how you STL library implements things, I think the second version could involve two less addition/subtractions per iteration. In …

Member Avatar for dospy
0
182
Member Avatar for meli123

OK, so show us a "Hello World!" program and we can try from there...

Member Avatar for Taywin
0
106
Member Avatar for MooGeek

[QUOTE=jingda;1642504]I am doing for android, can't sell it on the android market cost I need to pay. I try uploading the app on the net and see whether you guys can download it to your phone.[/QUOTE] Are you still doing this? I'm really keen to use something for my honeycomb …

Member Avatar for Netcode
0
204
Member Avatar for meli123

I guess you could try: [code] int main() { bool t = true; bool f = false; std::cout << "true = " << t << std::endl; std::cout << "false = " << f << std::endl; return 0; } [/code] For me this prints out [icode] true = 1 false = …

Member Avatar for mrnutty
0
96
Member Avatar for hariharan89

For me, this function is declared in [icode]$/modules/highgui/include/opencv2/highgui/highgui_c.h[/icode] (in Open CV 2.3)

Member Avatar for hariharan89
0
124
Member Avatar for hujiba

Hi there, well done for getting your function to work as you wanted :o) Now that it's working you could do a little tidying, since [icode]choose_number[/icode] is a little more verbose than it could be. In fact, the whole thing only needs one line: [code] int choose_number( int option_a, int …

Member Avatar for doug65536
0
170
Member Avatar for garu525

You can save some space by just losing all the temporary variables, but your basic algorithm is pretty much the fastest you can do in general. I'd probably just write: [code] void inverse ( unsigned *ip, unsigned *p, unsigned n ) { for ( unsigned i = 0; i < …

Member Avatar for mbundgaard
0
943
Member Avatar for coolbeanbob

You seem to be a little confused about defining and using functions in C++. Currently your program looks like this: [code] int main() { void printArray(int array[]); void printVector(vector<int> &v); void load(int array[], vector<int> &v); int array[30]; vector<int> vectorOne(300); printArray(array); printVector(vectorOne); load(array, vectorOne); return 0; } [/code] This doesn't do …

Member Avatar for raptr_dflo
0
181
Member Avatar for ravenous

Question for anyone using KDevelop: Is it possible to have a "workspace" containing multiple projects, like in a MS Visual Studio "solution" (or Code::Blocks or Codelite etc)?

Member Avatar for mike_2000_17
0
438
Member Avatar for XodoX

You can append to a text file using the [icode]std::ios::app[/icode] flag when you open it. So, if you want to read in from one file and append the contents to another file, you can do something like: [code] /* Open the input file & check that it opened OK */ …

Member Avatar for raptr_dflo
0
1K
Member Avatar for crapgarden

The "odd code" is the memory address of the first element of the array, since that's what your accessing by giving the name of the array. In the second case, you're using a [icode]char[/icode] array, which is treated in a special way, so that you can do something like: [code] …

Member Avatar for crapgarden
0
100
Member Avatar for stupendousomega

[QUOTE=dionisov;1633130]Can't u use an array? [CODE] #include <iostream> using namespace std; main() { short variable_number; cin >> variable_number; int *my_var = new int[variable_number]; for(int i = 0; i< variable_number; i++) { my_var[i] = 1; } return 0; }[/CODE][/QUOTE] To be a little pedantic, that code has the potential to leak …

Member Avatar for dionisov
0
7K
Member Avatar for ben1996123

If you've downloaded a bunch of .cc and .h files then you have the source files for the library. In this case, the easiest thing to do is to copy the files into a directory in the directory where you have the source for your project and then simply add …

Member Avatar for ben1996123
0
238
Member Avatar for ztdep

Forward declarations are really useful for helping to remove build dependencies that can lead to excessive compilation times. For that reason, I would tend to favour forward-declaration over actually including the header file if possible. I would want to avoid a cyclic dependency as mike_2000_17 explained though, so weirdly I …

Member Avatar for ztdep
0
286
Member Avatar for ravenous

Hi, Firstly, sorry about the large amount of code in this question. OK, so I'm making a C++ wrapper for the [URL="http://www.gnu.org/software/gsl/manual/html_node/Matrices.html"][icode]gsl_matrix[/icode][/URL] struct and its associated functions. To make my approach a bit easier to extend to other kinds of gsl structs, I have a template base class called [icode]gsl_base[/icode], …

Member Avatar for ravenous
1
384
Member Avatar for gujinni

There are lots of ways that you could do this, but you'd have to say more about the rules that you have to follow. For example, is the order of the characters important? Do they always have to remain in a string? Are you allowed to use STL algorithms? With …

Member Avatar for theguitarist
0
266
Member Avatar for gujinni

[QUOTE=gujinni;1591951]how to convert this in turbo c++[/QUOTE] Don't bother. You should download a new compiler/IDE. There are plenty of threads on this forum discussing which ones are good. If I were you, I'd go and look at some of them and then you won't have these problems. To get you …

Member Avatar for gujinni
0
376
Member Avatar for Oliverpc

Why do you need to call the [icode]center()[/icode] function at all? If I was you, I would attempt to get all the data outputted in the right order first and then tidy the formatting up at the end. I suspect that it's more important that you present the right information …

Member Avatar for Oliverpc
0
201
Member Avatar for Thisisnotanid

As a bunch of other people have said, starting out manually compiling on the command line is the way to go. It's also the simplest for small projects. When you first start out, you probably won't be making projects with hundreds of files and many different build configurations to manage, …

Member Avatar for Moschops
0
238
Member Avatar for MareoRaft

I think that they compile to the same thing. I might be mistaken, but I think that there is an implicit [Icode]void[/Icode] argument to all functions that appear to take no arguments.

Member Avatar for Raphaelnad
0
458
Member Avatar for Peter4n31

I have no idea what this code is supposed to do, but lines 6,7 and 8 look suspicious to me. What does UpdateAll() do? Does it affect the value returned by LastChild()? I'd be tempted to go for something more like: [Code] for( SceneNodeIterator it = FirstChild(); it! = LastChild(); …

Member Avatar for Peter4n31
0
192
Member Avatar for laim

What exactly is the problem? The only thing that I can see that might be a problem is that the LHS and RHS matrices might have their indices the wrong way araoud (I think that this is a mistake I made the other day too when I was answering a …

Member Avatar for laim
0
128
Member Avatar for dgreene1210

[code] int main (void) { int num1, num2, num3, float num4, int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8); getInput; calculate; printTable; return 0; } [/code] should be something more like: [code] int main () { int num1, num2, num3; float num4, …

Member Avatar for raptr_dflo
0
172
Member Avatar for dev344

The things after the colon ('[icode]:[/icode]') are the [i]initialisation list[/i]. This is a way to pass values to the constructors of member variables of a struct or class. It has essentially the same effect as writing: [code] SockerManager::SocketManager() { sockets = 0; events = 0; nSockets = 0; } [/code] …

Member Avatar for dev344
0
146
Member Avatar for laim

You have some confusion between types in your [icode]Exercises::Multiply[/icode] function. I think it should be something more like: [code] void Exercises::Multiply(const CMatrix& _rLHS, const CMatrix& _rRHS, CMatrix& _rResult) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { /* …

Member Avatar for laim
0
144
Member Avatar for George91340

You probably need to provide more details about your problem, such as an example of the file that you're trying to read in, and maybe some code that you've written yourself to try and solve the problem. Also, you should probably explain exactly how nested for loops are involved here?

Member Avatar for raptr_dflo
0
371
Member Avatar for nocloud

If you have to give another class access to private variables, you can have a member function that returns a pointer or reference to the variable: [Code] class X { public: double &get(); private: double y; }; [/Code] This gives control over which private variables are exposed, so I find …

Member Avatar for nocloud
0
954
Member Avatar for ztdep

You should consider using a [icode]std::map[/icode] to store your matrix values, rather than the system of [icode]std::vector[/icode] objects that you currently have. This will make the class smaller, clearer and also make the retrieval of values faster. To simplify vijayan121's excellently comprehensive example, so it's easier to see where the …

Member Avatar for vijayan121
0
189
Member Avatar for dilequeno

is that example the exact format of the file? Or are the track numbers that you put in just comments? If you're just separating the blocks with a line break, you can use [icode]getline[/icode] to read each line into a string, but check each one and start a new block …

Member Avatar for Ancient Dragon
1
321
Member Avatar for luislupe

I would be careful about doing this. The [icode]std::vector[/icode] container stores its contents in a contiguous portion of memory. If you resize the vector at any point, either directly by calling [icode]std::vector::resize[/icode] or indirectly, by calling [icode]std::vector::push_back[/icode] and the space available in the currently allocated memory for the vector isn't …

Member Avatar for ravenous
0
221
Member Avatar for lochnessmonster

Have you had a look at the header that defines it? That's probably a good place to start :0) you can also find details about it on cplusplus.com. @Thecoolman5: I'd also recommend that you go and look it up too, since your answer indicates that you possibly don't understand how …

Member Avatar for vijayan121
0
120
Member Avatar for montjoile

[QUOTE=montjoile;1574533] Why I have to put [COLOR="Red"]*[/COLOR] on the right side of the name of the type of data?? Why it doesn't work with: [CODE] *r=([COLOR="Red"]*[/COLOR]nodo)malloc(sizeof(nodo));[/CODE][/QUOTE] Because [icode]nodo[/icode] is treated as a kind of type, like [icode]int[/icode], whereas [icode]r[/icode] is a variable. So, having [icode]*nodo[/icode] makes no sense; you wouldn't …

Member Avatar for montjoile
0
118
Member Avatar for smrati.katiyar

I think that the number that you get out when you do this is undefined and compiler specific. For example, I just get 0, which I think is the standard thing that I get whenever the conversion to [icode]int[/icode] can't be done. The large number is just a kind of …

Member Avatar for Ancient Dragon
0
128
Member Avatar for Geek-Master

[code] typedef vector< vector< double > > matrix; typedef vector< double > row; matrix M; row R; /* Add some numbers to a row */ R.push_back( 1 ); R.push_back( 4 ); R.push_back( 2 ); /* Add the row to the matrix */ M.push_back( R ); // Repeat for all your …

Member Avatar for Hialek
0
5K
Member Avatar for JordanHam
Member Avatar for DarkPyros

This looks like it's C, not really C++. Anyway, some points: [list] [*]I think that line 12 should be [icode]scanf ("%d", &num2);[/icode], instead of [icode]scanf ("%d", num2);[/icode]. [*]You have an extra ';' on the end of line 14 [*]Line 17 gets a number from the user and puts it in …

Member Avatar for DarkPyros
0
184
Member Avatar for tubby123

In regard to your "doubt-2", I don't think what you found is correct. Consider this test program: [code] #include <stdio.h> int main() { int x = 2, y = 5; int* a[2]; int* p; p = &x; a[0] = p; a[1] = &y; printf( "p = %p -> %d\n", p, …

Member Avatar for ravenous
0
208
Member Avatar for Falcon143

You might be able to find something about this by looking at [URL="http://www.ffmpeg.org/"]ffmpeg's[/URL] libav. If you're thinking of looking at video in C, libav is a reasonable place to start, rather than code something from scratch by yourself.

Member Avatar for ravenous
0
43
Member Avatar for snipermann

[URL="http://xerces.apache.org/xerces-c/index.html"]xerces[/URL] is a reasonably good C++ xml parser. There's a barrier to learning to use this kind of thing, since you have to put some work into getting things set up, however the benefits are huge. For example, say you want to read a different kind of file, or the …

Member Avatar for ravenous
0
318

The End.