1,177 Posted Topics
Re: Please post the smallest compilable code that will produce this error. "undeclared identifier" in this case probably means that you didn't include the header file? Dave | |
Re: I would put the numerical representation of the number into an std::string. From here you can access each digit separately: [code] std::string number = "123"; std::cout << number[0]; //outputs '1' [/code] You would then have to have a giant switch statement to convert a '1' to "one", etc. Hope this … | |
Re: You're going to need to be a lot more specific than that! How are we supposed to know what you are trying to do?? Dave | |
| |
Re: getline() from iostream will do the reading and you should use ofstream to do the writing. Give this a shot. If it doesn't work, post a < 10 line demonstration of the problem. Dave | |
Re: Look into "exceptions" (throw and catch). It won't be a magic solution, you have to predict the run time errors. But it is better than nothing. Dave | |
Re: Can you take the input as a string and then check the length. If it is more than say 10 characters you can output "please don't input such large numbers" or something. | |
![]() | Re: First, you should fill these in!! [code] // void // Purpose: // Inputs: // Ouputs: [/code] They will really help your structure/logic. I am concerned that your sort() function should not be doing anything with fstream - you should read the data elsewhere and pass it to sort(). I would … ![]() |
Re: I wouldn't do everything in the constructor. I would make it more like this: [code] Search mySearch; mySearch.SetText("This is the text I want to search in"); mySearch.SetSearchString("want"); bool found = mySearch.Search(); [/code] This way you also can use the result in the calling function. Dave | |
Re: What is the error you are getting? Can you provide the smallest compilable piece of code that will produce this error, along with sample input, expected output, and current output? Dave | |
Re: Since there is no question, should this be moved to "code snippets"? | |
Re: You can access each digit using a std::string [code] std::string number = "NAB"; for(int i = 0; i < number.size(); i++) std::cout << number[i] << std::endl; [/code] Dave | |
Re: I posted an example of how to use boost regex in this thread: [url]http://www.daniweb.com/forums/thread288358.html[/url] Maybe it will get you started. Dave | |
Re: Please use more descriptive titles in the future! | |
Re: fyezool, Of course we can appreciate that English is not your first language, but please try to use "proper" English, rather than numbers and single letter words ("u 2", "sorry 4", etc) Welcome to Daniweb. Dave | |
Re: You should see if there is an XML parser library for c++. This is pretty much exactly the idea of XML. Otherwise, just read in line by line, check for '[', then keep reading all of the lines until you hit another '['. | |
Re: You should look into using ifstream. fseek, fgets, strtok, strchr, etc are all depricated. | |
Re: Please try to pose your question in a concise form such that it can benefit others in the future. That is, ask a question about c++, not about your program. Some recommended reading... [url]http://daviddoria.blogspot.com/2010/05/problem-abstraction-helping-others-help.html[/url] Dave | |
Re: Yes, always use std::string!! What I really wanted to say was MAKE ABSOLUTELY SURE you comment any lines like [icode] 1<<x;[/icode] EXTREMELY well and TEST THEM INDIVIDUALLY FIRST. I would be extremely annoyed if I found some code like that without a comment with the equivalent math or pow() style … | |
Re: NathanOliver - It sounds like he wants to do something with this function: [url]http://msdn.microsoft.com/en-us/library/dt12193b(VS.71).aspx[/url] I've never heard of the concept, but it doesn't sound like tie() does any actual outputting, but rather just forces an output to finish before starting an input. What NathanOliver just recommended was in your original … | |
Re: Does this help? [code] int RandomInt(const int MAX) { //produce an int from 0 to MAX-1 return rand() % MAX; } [/code] Dave | |
Re: - Please use code tags and reasonable indentation. - Please tell us an example input, the current output, and the expected output. Dave | |
Re: I am using KDevelop and I got the same error (/bin/sh: double: No such file or directory). I added this to the top of your code instead: [code] #define COMPLEX std::complex<double> [/code] And it compiled and ran fine. It must be something wrong that we are doing with the -D … | |
Re: This code: [code] #include <iostream> #include <vector> using namespace std; int main() { #include <vector> std::vector<double> a; int i =0; while(1) { a.push_back(i); i++; } return 0; } [/code] produces [code] terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc [/code] | |
Re: This is a pretty standard usage of switch. Have a look here: [url]http://msdn.microsoft.com/en-us/library/k0t5wee3(VS.80).aspx[/url] | |
Re: I'd suggest building the smallest tree possible (a root and one leaf) and then stepping through with a debugger. Then you can see what is going on when you know exactly what SHOULD be going on. Good luck, Dave | |
Re: Can you tell us the application? Maybe someone will have a suggestion. Storing things as a void* always sounds like a bad plan to me... | |
Re: Can you use a std::vector<list>? Also I would be very careful with the name "list". If somewhere else std::list gets included, then you're going to have conflicts. Dave | |
Re: I don't understand the problem? I removed all of the code that we can't compile and the text and came up with this: [code] #include <iostream> #include <string> using namespace std; int main() { string test; cout << "1: " << endl; getline(cin, test); cin.ignore(); cout << test << endl; … | |
Re: After some googling, it looks like if you want a really robust solution you should use something like Boost Regex [url]http://www.boost.org/doc/libs/1_35_0/libs/regex/doc/html/index.html[/url] If any of the experts here have a way to do it with std::string and std::algorithm only, that would be nice, but as soon as you allow multiple wildcards … | |
Re: This is surely an OS dependent question - I'd say the only way to do it in c++ would be with a system() call to the appropriate OS command. Dave | |
Re: You should use a vector<string> or vector<char> if you want to store things besides ints. Better yet, why not use a stack<char> which provides all of the functions you are looking to implement already? | |
Re: Please try to make your titles and questions as abstract as possible. This way the "next guy" can search and find something usable. If you ask "How do I randomly select an element of an array?" that is much more reusable than "How do I make a horse finish first?". … | |
Re: Welcome to Daniweb! I have a few suggestion that will help you get the help you need. 1) Please use code tags. It will help everyone read your code. 2) Try not to post hundreds of lines of code. Each line takes the reader time to analyze, so you should … | |
Re: First, please use proper English (i.e. not "plz") when posting on Daniweb. I would use an std::map. Traverse the string a character at a time. If the element doesn't exist in the map, add it to the map as a key with value=1. If it does already exist in the … | |
Re: Take a look at sort() from <algorithm> | |
Re: Welcome to Daniweb! - Please use code tags when you post code. It makes it much more readable for other uses. - Please try to make the example as simple as possible to demonstrate the problem you're having. For example, in this case the drawing to the screen is taking … | |
I saw a post today that I said "hm I'd like to have a closer look at that tonight". Is there anyway to "mark" or "flag" a thread to put it in your "favorites" or something like that? Dave | |
Hi Dani et al., I don't know if you'll have any interest in this, but I'm going to describe what I have done over the past couple of years on an open source project that I think could be extremely beneficial to Daniweb as well. The project I work on … | |
![]() | Re: There is a project called OpenCV (CV = Computer Vision) that is all about this stuff. You can also look at VXL, ITK, and VTK. Matlab also has many many image processing functions. Good luck, Dave |
Re: Instead of [icode][k++][/icode] why don't you try incrementing k outside of the [] so you know for sure when it is happening. Then output k and compare it to yourString.size() and make sure everything seems kosher. This error definitely means you are accessing the 5th character in a string of … | |
Re: What do these course numbers refer to? What are your other options? [this is not a c++ question and should be moved elsewhere] | |
Re: You should definitely look into using a std::vector<int> instead of an array of ints. You can push_back() each element so the vector will grow to accommodate the new guesses. You could also use an std::set instead of an std::vector to "automatically" tell if a number had already been guessed. If … | |
Re: If it were my problem I would copy everything into a new folder and start deleting things. For example: [code] bool isWriteable() { return m_Access == ACCESS_WRITE; } [/code] surely doesn't have anything to do with the problem. Once you've done all you can do, I bet you will have … | |
Re: First, why not change the headers to [code] #include <memory.h> #include <cstdio> #include <cstdlib> //required for system() #include <iostream> [/code] to use the "new" way. Also, I think the "c++ way" is to use cout and endl instead of printf and \n. Now to the main problem The first output … | |
Re: Sure, just set a member variable before your destructor gets called, and reference that variable from the destructor. Dave | |
Re: Don't use itoa, but rather use std::stringstream | |
| |
Re: What is the problem? Can you simplify the code into a <20 line demonstration of the problem? | |
Re: Also, there is no reason to use global variables here. Define number1,2,3 in main and then pass them by reference to the functions. Dave |
The End.