466 Posted Topics
Re: 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] | |
Re: [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; … | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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. | |
Re: 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 … | |
Re: [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. … | |
Re: 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 … | |
Re: 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 … | |
Re: OK, so show us a "Hello World!" program and we can try from there... | |
Re: [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 … | |
Re: 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 = … | |
Re: For me, this function is declared in [icode]$/modules/highgui/include/opencv2/highgui/highgui_c.h[/icode] (in Open CV 2.3) | |
Re: 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 … | |
Re: 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 < … | |
Re: 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 … | |
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)? | |
Re: 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 */ … | |
Re: 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] … | |
Re: [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 … | |
Re: 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 … | |
Re: 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 … | |
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], … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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, … | |
Re: 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. | |
Re: 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(); … | |
Re: 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 … | |
Re: [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, … | |
Re: 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] … | |
Re: 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++) { /* … | |
Re: 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? | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
![]() | Re: [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 … |
Re: 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 … | |
Re: 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, … | |
Re: 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. | |
Re: [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 … |
The End.