daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

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 try to post only lines that are relevant to your question.

3) Try to "abstract" your question into a c++ question. That is, rather than "How do I search for a student?", instead say "How do I find a string in a a vector of strings?" or something similar.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

As usual everything with boost is insanely complicated and the examples aren't very helpful...

I believe this does what you want (remember to link to boost_regex)

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;

int main(int argc, char** argv) 
{
   std::string strRE = "Hello.*World.*Goodbye";
   
   boost::regex re(strRE.c_str());
   
   std::string PositiveTest = "HelloEveryoneWorldThenGoodbye";
   std::string NegativeTest = "Test";
   
    if (boost::regex_search(PositiveTest, re))
    {
      cout << "Found." << endl;
    }
    else
    {
      cout << "Not found." << endl;
    }
   
    if (boost::regex_search(NegativeTest, re))
    {
      cout << "Found." << endl;
    }
    else
    {
      cout << "Not found." << endl;
    }
  return 0;
 
}

Though you may learn something by following NathanOliver's suggestion, using Boost you don't have to reinvent the wheel :)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

After some googling, it looks like if you want a really robust solution you should use something like Boost Regex

http://www.boost.org/doc/libs/1_35_0/libs/regex/doc/html/index.html

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 I think it gets pretty tough.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You say "one last question" but I didn't see any questions before that? Also, what do you mean by choice 3 and 4? Please break you question into small parts and give them a shot. If you have a problem with a particular piece of code (maybe < 10 lines worth) we'll be happy to look at it.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You're right Ed, but I was assuming he wanted to find the frequency of more than 1 letter.

daviddoria 334 Posting Virtuoso Featured Poster

Again, "thankz" is not proper English.

daviddoria 334 Posting Virtuoso Featured Poster

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 map, increment the associated value.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What have you tried so far? When you come across a specific problem, we'll try to help you out.

daviddoria 334 Posting Virtuoso Featured Poster

- Please use code tags and reasonable indentation.

- Please tell us an example input, the current output, and the expected output.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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 up a significant portion of the code, and has nothing to do with the problem at hand. Then provide sample input, your current output, and your expected output to this small problem. It is a classic case of "help us help you"!

- PLEASE try not to use global variables. It is almost always a bad idea!

- Consider using 'else if' instead of a bunch of independent if statements on the same condition. I hear it's faster. You could also try a swtich() statement.

Please consider these things and post what you come up with!

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Yes, always use std::string!!

What I really wanted to say was MAKE ABSOLUTELY SURE you comment any lines like 1<<x; 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 statement as a comment. Even though it is 10x faster :)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Very cool. I made a "Follow Up" folder and then I can use "Move to folder" to put threads in there.

Thanks!

daviddoria 334 Posting Virtuoso Featured Poster

I recommend you do some googling for "static libraries c++" and "c++ linking". Then, I recommend you build this program manually (without eclipse) using g++ and the -L and -l flags. THEN once that works, the only problem is doing it in the "language"/framework of Eclipse.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Agni -

I am only speaking from one success story, but it has worked EXTREMELY well with for me the VTK project. With Daniweb C++, if someone asks something about converting numbers to strings, I typically tell them "hey go check out stringstream, here are some links to the man page etc". If instead we pointed them to an example usage, odds are they can figure it out from that.

I agree that it will not match their question EXACTLY, but that is even better, so they can learn to learn in the process!

I also agree that the archive cannot become enormous. I initially see about 20-50. This is a very manageable number. I made 500 for VTK, and it is still reasonably manageable. We just have to be careful about what to add to the examples archive.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

jwenting - Clearly we would omit those and only use "good" questions and answers.

bandtank - Sounds good to me. I volunteer to be this "reviewer" if that's all it takes to give this a try.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Hm, but every time I reply to a thread, it gets added to my subscription list (which I enjoy, so I can follow up). So if I just mark one more (the one I want to remember to follow up with) as "subscribe", it won't stand out so I'll see it later. Know what I mean?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Take a look at sort() from <algorithm>

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

I downloaded it and built it. This produced 3 ".a" files (static libraries). I had to link the program to these libraries so that the symbols were defined. This is done manually with

g++ -l[library1] -l[library2]

(ensuring the library path is either on your LD_LIBRARY_PATH or you tell g++ with -L)

In Eclipse, surely you can set libraries to link to without needing this syntax.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

Is your project set up to link to all 3 libraries that build with sparselib?

daviddoria 334 Posting Virtuoso Featured Poster

A fancier way to reverse the string can then be used:

std::string reversedString = std::string ( yourString.rbegin(), yourString.rend() );

You will also want yourString.compare(otherString) Give these revamps a shot and let us know how it turns out.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

Linux has the concept of pipes to communicate between executables. Since you are saying "exes" I'm assuming you're in Windows, in which case I have no idea. You could always write to a file from program A and then read the file from program B, the problem would then be how do you notify program B that the file has been changed?

daviddoria 334 Posting Virtuoso Featured Poster

Instead of [k++] 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 length 4, or something equivalent.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Sure, sure, but I mean what are the course titles? At which institute are they being offered?

daviddoria 334 Posting Virtuoso Featured Poster

I guess it depends on the logic of the program. You may want to use Fbody's suggestion of a bool array because say the number you guess is greater than the secret number - you'd want to mark ALL of the number above the guess as "used" because you've already effectively guessed that whole range.

daviddoria 334 Posting Virtuoso Featured Poster

What do these course numbers refer to? What are your other options?

[this is not a c++ question and should be moved elsewhere]

daviddoria 334 Posting Virtuoso Featured Poster

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 the size of the set doesn't change when you insert(), then the number was already in the set!

Let us know if you have problems trying any of this.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Here is how you use ofstream:

http://www.java2s.com/Code/Cpp/File/Toreadorwritetoafileyouincludefstream.htm

I'd definitely stop using fopen :)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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:

#define COMPLEX std::complex<double>

And it compiled and ran fine. It must be something wrong that we are doing with the -D syntax.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

First, why not change the headers to

#include <memory.h>
#include <cstdio>
#include <cstdlib> //required for system()
#include <iostream>

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 ("opened input") is displayed, but the second one ("opened out") is not. Maybe someone can help you with finding the problem now that it is narrowed down to these few lines.

std::cout<<"opened input.txt " << std::endl;
    scanf("%d", &n);
    scanf("%d", &m);
	
    fp = freopen("outfile.txt", "w", stdout);
    if(fp == NULL) 
    {
	cout<<"failed to open out.txt \n";
	system("PAUSE");
    }

cout<<"opened out.txt" << std::endl;

Something must be happening that is breaking the standard output stream. If you're just trying to write ascii files, you should use ofstream.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If it were my problem I would copy everything into a new folder and start deleting things. For example:

bool isWriteable()
	{
	    return m_Access == ACCESS_WRITE;
	}

surely doesn't have anything to do with the problem. Once you've done all you can do, I bet you will have a < 20 line program on your hands. This will either point you directly to the source of the problem, or allow someone here to take a quick look.

daviddoria 334 Posting Virtuoso Featured Poster

Dani, are you back in action? Any thoughts on this? S.O.S. makes some good points, but I'm still inclined to try it. In the last couple of days I've seen several questions that could be answered with a link to an example. As the list of examples grows so would the ability to answer questions with links to them!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If you're storing things in an array (contiguous memory), I believe the only way to delete an element from the middle is to shift all of the elements after it to the left. If operations like this are frequently required, the linked list data structure is preferred to the array.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Why not use a std::list instead?

daviddoria 334 Posting Virtuoso Featured Poster

What is the problem? Can you simplify the code into a <20 line demonstration of the problem?

daviddoria 334 Posting Virtuoso Featured Poster

Don't use itoa, but rather use std::stringstream

daviddoria 334 Posting Virtuoso Featured Poster

I don't see any reason to use strncpy? Why not just ifstream everything into a few std::vectors, use sort() from <algorithm> and then do any conversions to string as we just showed you?

daviddoria 334 Posting Virtuoso Featured Poster

If anyone is interested, VTK has sql support:

http://www.vtk.org/Wiki/VTK/Examples/Databases/SQL/MySQL/ConnectAndRead

It is quite a bit of overhead to bring in such a big library just for this, but it's better than nothing!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Nope.

void NumberToString()
{
  int intNumber = 13;

  //put the number in a stringstream
  std::stringstream ss;
  ss << intNumber;

  //get the number out of the stringstream as a string
  std::string strNumber;
  ss >> strNumber;
  
  std::cout << "strNumber = " << strNumber << std::endl;
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Oops yes yes you are right. The point was look into std::stringstream :)

Sorry for the confusion.

daviddoria 334 Posting Virtuoso Featured Poster

I think what you are trying to do is convert a non-string to a string representation, yes?

If so, look into std::stringstream. You can simply do:

std::stringstream ss;
ss << yourThing;
std::string >> ss;

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd say 'a' is the most important. 'b' is really part of 'a'. 'c' is probably referring to the functions in <algorithm>, which C certainly does not have. 'd' is correct, void pointers and preprocessor directives are nightmares!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Why not make it a member variable if it is being accessed by member functions? Does it need to be accessed outside of the class? If so you can provide an accessor function or make it public.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I only have an answer to the first question. I ALWAYS reference member variables with this-> . I've found that it makes code much much more readable. If you have a long function, reader immediately know that this is a member variable and don't have to spend time looking around to see if it was passed to the function, declared inside of the function, or a member variable. I don't believe there are any times when using this-> is harmful, but there are certainly times where NOT using it can produce an ambiguous case that will cause you headaches.

Good luck with your second question - I'd actually start a separate thread in the C forum for this question (with a better title :) )

Dave

daviddoria 334 Posting Virtuoso Featured Poster

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

daviddoria 334 Posting Virtuoso Featured Poster

Why is Bugarr defined in that header? If it is not part of the class (which it is not, it is a global variable), then it should probably not belong in the class's header.