1,288 Posted Topics
Re: Now that we have C++11, which comes with threads, we no longer need anything platform specific. The best book on threading with C++11 I've found is the Anthony Williams book "C++11 Concurrency in Action". Williams' company has been selling a threading library for years and he really knows his stuff, … | |
Re: > when I search "car" Maybe you should try searching for "Carr". | |
Re: for (;;) { cout << "|* * * * * *|---------------------|" << endl; cout << "| * * * * * |---------------------|" << endl; cout << "|* * * * * *|---------------------|" << endl; cout << "| * * * * * |---------------------|" << endl; cout << "|---------------------------------|" << endl; … | |
Re: > I'm starting to hate the idea of OOP. OOP is a way of thinking about and structuring code. Your problems above are all with syntax. | |
Re: > if the structure were a class In C++, a struct IS a class. A class IS a struct. The only difference is the default member visibility (and related default inheritance). Everything you know about a class in C++ you also know about struct, because they're the same thing. | |
Re: A vector springs to mind: /*Item.h handles the item in game*/ #ifndef ITEM_H #define ITEM_H #include <string> #include <vector> class Item { public: Item(std::string IDesc, std::string IName) : name(IName), desc(IDesc), used(false){}; ~Item(){}; bool useable(){ return !used; } void useItem(){ used = true; } std::string getName() const { return name; } … | |
Re: Debug your code. Output the value of `pass` and `fpass` at the start, and each time you think they should (or may) have changed. | |
Re: Mike explains it heres https://www.daniweb.com/software-development/cpp/tutorials/466177/understanding-c-from-source-to-binaries in the section headed "Dynamic vs. Static Libraries" | |
Re: You can. However, what do you actually need from the image library? If you just need to be able to read images into memory, and write them again afterwards, and you'll do the manipulation yourself, ImageMagick might be a bit overpowered. There are many, many image libraries available. | |
Re: > Shouldn't there be a conflict? No. I agree, that you *could* create a programming langage in which you wouldn't be allowed to create two objects with the same name in the way that you can in C and C++, but that's not how C and C++ were designed. In … | |
Re: On the command line, enter `gcc --version` | |
Re: Make a vector of string. Use std::getline to read in one line at a time, and push_back each line onto the vector. | |
Re: You've got a function named main somewhere else as well. Perhaps you are compiling this code and some other code into the same program. | |
Re: What do you mean when you say "i've done atleast 4 programs"? Do you mean that you have four separate programs, all compiled and linked and reay to run (and you can run each of them separately right now), and you want to write a new program that will start … | |
Re: Add `#include <stdafx.h>` to your code. Before whatever you had to include to get this error. | |
Re: I've spotted a pattern to your questions. You write something that compiles, then when it turns out to be wrong, you come here and ask us to do your homework for you. Perhaps you should be putting a bit more effort into thinking about the problems and, more importantly, testing … | |
Re: A vector of strings comes to mind. `vector<string> stringStore;` Every time you need to add one, just add it to the end of the vector `stringStore.push_back(nextString);` Similarly for `double` values. | |
Re: Generally, if you cannot open a file that does exist, it's because you're not looking in the right place. Start by replacing the filename with the complete path and see if that works. If it does, you know that your program is looking in the wrong place. How do you … | |
Re: In your header file, you promised that *you* would be writing the default constructor. Like this: `Captain();` So because you made that promise, you have to write a default constructor of this form: Captain::Captain() { } but you didn't. So the compiler complains that it can't find the default constructor … | |
Re: We would be remiss if we did not point out that `rand` is deprecated and really should not be used. Some of the implementations of it are fist-bitingly bad. http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful Welcome to C++11's bright world of <random> :) | |
Re: > Am I going on this the wrong way?? Yes. To begin with, it doesn't make any sense to me that a RoomOne is a kind of StoneAdventure (and that's what inheritance does; if X inherits from Y, then X *is a* specialised kind of Y, and can be used … | |
Re: ` cout << mychar << endl;` This line is passing a char pointer to `cout`. When `cout` is given a char pointer to operate on, the function executed looks like this: Output the char being pointed to, and the next char, and the next, and so on, until you find … | |
Re: Your code is littered with odd symbols. Like the one at the satrt of line 4. No idea what they're doing there. Get rid of them. In your code, every time you have one of these `{` you're going to need one of these `}`. You're missing lots. At the … | |
Re: Your function name does not match the instructions. | |
Re: `gpof EXECUTABLE-FILE gmon.out > outfile.txt` Your command line doesn't have the executable filename. | |
Re: I'm not going to do your homework for you, but here is a way to output a char's numerical respresentation: `std::cout << (int)someChar;` | |
Re: Even a four byte unsigned long int has a range of 0 to 4,294,967,295. This is more than 4 billion and more than a hundred thousand. Unless you're using a PC from a very long time ago (decades ago), your long ints are at least this big. So what is … | |
Re: If you have a modern compiler, you can do something like this to initialise class members: ` vector<int> vec = vector<int>(5); ` | |
Re: #include <iostream> int main() { while(1) { std::cout << "1" << std::endl << "12" << std::endl << "123" << std::endl << "1234" << std::endl << "123" << std::endl << "12" << std::endl << "1" << std::endl; break; } } | |
Re: Reading binary image files and getting the data from them is not simple. For some formats, like JPG, it's really not simple. Unless you're doing this because you really want to know baout how the information is stored in the file formats, just use an image library. It's what everyone … | |
Re: A simple static library is a bunch of ".o" files, stuck together. You need to read Mike's overview: https://www.daniweb.com/software-development/cpp/tutorials/466177/understanding-c-from-source-to-binaries | |
Re: > if you cant help so please @priteas so please staw away from other buisness I think you need to rephrase that. Try something like this: > I need to give three advantages of using procedures. I'm not sure exactly what the question is asking. I think that a procedure … | |
Re: Without using a library, you're simply going to have to do it yourself. Frankly, you need to start by thinking rather than coding. You can read the xml file easily. Open it, read in data. But that just gets you a lot of strings. How do you intend to organise … | |
Re: `#include "action.cpp"` This tells the preprocessor to paste the contents of the text file "action.cpp" into this position, just as if you had yourself manually typed it in at that position. So, you have a definition of the function in action.cpp, and a definition of the function in main.cpp This … | |
Re: The linker can't find those functions. Assuming you've not got the names of the functions wrong, and that they're library functions, you need to make sure you have the library containing those functions, and make sure you have told the linker what those libraries are named, and make sure you … | |
Re: The `mode` average is the value that comes up most frequently. Get all the values, look at each one in turn, and count up how many of each there are. | |
Re: Here is a link presenting various options. Decide now which operating system you're using (windows or other), and decide if you want an IDE or if you want to do your own compiling/linking, and then pick one from the list. http://www.cplusplus.com/articles/j8hv0pDG/ | |
Re: http://www.cplusplus.com/forum/beginner/1988/ | |
Re: If the compiler (actually pre-processor in this case) cannot find a file it is looking for, then you have not told it where to look, or put the file in the wrong place, or misnamed the file. What is the exact error message? | |
Re: Depends on your version of Visual Studio. http://stackoverflow.com/questions/2676417/how-do-include-paths-work-in-visual-studio | |
Re: C++ strings come with functions to find substrings inside them. http://www.cplusplus.com/reference/string/string/find/ | |
Re: You have a pointer, `fp`, that you create and use but you never, ever set it to anything. It will be pointing to some random location in memory. This is very bad. | |
Re: `startingExpr[i]` is a char, and `newChar` is a string, so `startingExpr[i] = newChar;` makes no sense; you're trying to assign a string object to a char. This being C++11, we have a to_string function now for converting an int to a string: http://en.cppreference.com/w/cpp/string/basic_string/to_string ![]() | |
Re: > conversion from 'std::stack<int>*' to non-scalar type 'std::stack<int>' requested `stack<int> resultStack = new stack<int>();` The bit on the right gives you a *pointer* to a `stack<int>`. You're trying to store that pointer value as a `stack<int>` object. This makes no sense. A `stack<int>*` is not the same as a `stack<int>` … ![]() | |
Re: I see you changed your question; first, you asked about this: `foo&(){...` and then you changed that to this: `int& foo(){...` Presumably, the first one was a typo. In C++, the second *is* invalid (and the first, but I'm callign that a typo). You *can*, however, return a **const** reference … |
The End.