NathanOliver 429 Veteran Poster Featured Poster

you just need the ignore call after you do cin >> c_n_p; . When you change from unformatted input to formatted input you will need to call ignore.

getline(cin, something);
cin >> foo;
cin.ignore(80, '\n');  // need this here for getline to work
getline(cin. somethingelse);

// without a cin >> you don't need anything
getline(cin, something);
getline(cin, somethingelse);
getline(cin, bar);
// no ignore here since they are all getline calls

the reason for this is that cin >> foo leaves the newline in the input buffer where getline(cin, foo) will extract the newline from the input buffer.

NathanOliver 429 Veteran Poster Featured Poster

Looks that way David. From what I found it makes sure that the output stream is flushed before it allows any inputting to occur.

NathanOliver 429 Veteran Poster Featured Poster

do you want to store different types of data in this container at the same time?

Container stuff;
int a = 5;
char b = 'b';
double c = 3.14;
stuff.add(&a);
stuff.add(&b);
stuff.add(&c);
NathanOliver 429 Veteran Poster Featured Poster

if you want to get numbers from a and put them in c then you can do this

a >> x;
c << x << endl;
NathanOliver 429 Veteran Poster Featured Poster

try this

cin.ignore(80, '\n');
// instead of
cin.ignore();
NathanOliver 429 Veteran Poster Featured Poster

well if you have an equation and want to use it for different variables than you could put it into a function.

int Equation(int a, int b)
{
    int c = a * b + b - 5;
    return c;
}

// then in you code instead of writing out your equation every time you need if for different variables do this
int a = 2;
int b = 5;
int c = Equation(a,b);
int d = Equation(c,b);
// and so on

Then you can have cases where you 2 arrays and each corresponding element in the arrays needs to be processed. Using the same function as before you could do this.

int a[100], b[100], c[100];
// fill a and b with data
for (int i = 0; i < 100; i++)
{
    c[i] = Equation(a[i], b[i]);
}
// now the array named c has all of the results.
NathanOliver 429 Veteran Poster Featured Poster

It is nice to have differnt things to chose from though. Personaly I like the challange of figuering this stuff out. But yes its nice the people at boost already thought of this one

NathanOliver 429 Veteran Poster Featured Poster

There are a bunch of different cases you will have to use to solve this. First I would separate the extension from the file name. Then for a simple case like "*.txt" you would just use the extension string to match the file names.

std::vector<string> wordList;
std::vector<string> matches;
// fill the list with file names
// separate the filename and put the name in filename and
// the extension in extension.  here im doing it manually
std::string filename = ""; // nothing here since its just a wild-card
std::string extension = ".txt";
size_t size = wordlist.size();
size_t length;
// go through the vector and check just the extensions since
// the filename is a wild-card
for (size_t i = 0; i < size; i++)
{
    length = wordList[i].size();
    if (extension == wordList[i].substr(length - 4, length))
        matches.push_back(wordList[i]
}
// now you have a list of all the files that match the extension

For cases like "my*.txt" we would separate the file name and the extension again. So the filename string would be "my*" and are extension string would be ".txt". To solve this you can use the function find_first_of(). Pass in the first letter from the filename string and if it returns that there is a "m" in the string then you start a comparison against the two string until there is a mismatch or you reach the *.

std::vector<string> wordList;
std::vector<string> matches;
// fill the list with file names
// separate the filename and put the name in …
NathanOliver 429 Veteran Poster Featured Poster

if else statements do not get warped in brackets like you have here. the way they should look is like this

if (something)
{
    // code here
}
else
{
    // more code here
}

// and for nested statements
if (something)
{
    if (somethingelse)
    {
        // some code here
    }
    else
    {
        // else for somethingelse
    }
}
else
{
    // else for something
}
NathanOliver 429 Veteran Poster Featured Poster

You could have a newline in the input buffer that is getting extracted by the call to getline. That would give you an empty string. Try doing this.

//...
cin.ignore(80, '\n');
cout << "Enter serial number to be removed. Enter to quit:";
getline(cin, serial);
NathanOliver 429 Veteran Poster Featured Poster

Well if you have different variables you can do this

int a,b,c;
a = 1;
b = 2;
c = 3;
a = b + c;
b = a; // b is now a which is 5
NathanOliver 429 Veteran Poster Featured Poster

What have you tried so far?

NathanOliver 429 Veteran Poster Featured Poster

you could also use cin.get() to get rid of the newline.

NathanOliver 429 Veteran Poster Featured Poster

Because there is a newline left in the buffer from the call to cin >> gender . You will need to get it out before you call getline again. Narue has a good post about there here

NathanOliver 429 Veteran Poster Featured Poster

First void main is not standard. main should only return an int as per the ISO standard. Secondly all of your header files are deprecated. What compiler are you using? You might also want to change where you compare the user answer to the answer in the file. I would do it right after the user enters in there answer so they know right there if they got it wrong or not.

jonsca commented: Yup +4
NathanOliver 429 Veteran Poster Featured Poster

Ah I see. Well I guess he could code it himself to make it portable.

NathanOliver 429 Veteran Poster Featured Poster

Well he could use _stricmp(). According to my MSDN _stricmp() is ISO conformant.

NathanOliver 429 Veteran Poster Featured Poster

Could you post what you have now?

NathanOliver 429 Veteran Poster Featured Poster

One of the problems with palindromes is the formatting. In this case you have commas and when you reverse the string they will not line up right but the letters in the sentence is still a palindrome. One solution would be to strip all punctuation and spaces from the sentence and then reverse it and compare. So you would get this as input.

A Man, A Plan, A Canal, Panama

Strip out everything that isn't a letter or number

AManAPlanACanalPanama

Reverse

amanaPlanaCAnalPAnaMA

Then you can use stricmp() to test if they are the same. stricmp() is case insensitive so you wont have to worry about making the input all one case. Here is a link about stricmp(): http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.langref.doc/rzan5mst264.htm

NathanOliver 429 Veteran Poster Featured Poster

Change your do...while loop to a while loop and use k as your tracker for your exit condition.

while( k != myToken.size())
{
    char s = myToken[k];  // no ++ here
    // rest of your code here
    k++
}

The reason for this is that you are running to infinity with your current loop and as soon as k is larger then myToken.size() you get a failed assert. Having the loop as I presented will ensure that you do not go beyond the range of the string.

NathanOliver 429 Veteran Poster Featured Poster

Yes it is left to right but it isn't how you think it is. The object on the left calls its function with the object on the right as its parameter. So for you += example you would have

ob1.operator+=(ob2.operator+(ob3));

As you can see from this you are never calling a non const function in a const object. The const object keeps getting passed up the ladder. Let me know if you need a better explanation.

NathanOliver 429 Veteran Poster Featured Poster

I do agreee that vectors do have advantages but this is still c++. It is still usefull to know how to do these things because there are times when you would be better of with a 2d array instead of a 2d vector.

NathanOliver 429 Veteran Poster Featured Poster

You could define it like int* spaces[3];

NathanOliver 429 Veteran Poster Featured Poster

here you go solution

jonsca commented: Yep +4
NathanOliver 429 Veteran Poster Featured Poster

Addition is left to right in c++. So ob2 and ob3 are added together to form a const A. Then ob1 and that const A returned from the previous addition are added together.

ob4 = ob1.operator+( ob2.operator+(ob3) );

Hope this will clear that up for you.

NathanOliver 429 Veteran Poster Featured Poster

Personally agree with Narue that the question is misleading. The C++ STL and C's procedural programing have there advantages and disadvantages. I started off writing programs in basic on my TI85 so the first language I learned was a procedural language. Then I moved on to C++ and found a whole new world of options. Now I blend the two to suite my needs. The really important thing to learn is how to use both styles and then what style to use to solve a particular problem. If you get in the mindset that C++ must be better so therefore I will code in only C++ then you will be heading for trouble. Just because one can doesn't mean one should.

NathanOliver 429 Veteran Poster Featured Poster

Well if you have multiple records in one file and want them all you either need multiple objects or data members that are arrays. If you want each object to have just one set of values you will have to go one way. If you want the one object to hold all of the data then you will have to go another way. Let me know how you want to implement it and I can help you out.

NathanOliver 429 Veteran Poster Featured Poster

Why do you have multiple records in one file if the member variables of the class are not arrays. If they are arrays then you should use a while loop like you had and add a counter so you can input the values in the right index.

NathanOliver 429 Veteran Poster Featured Poster

That should be in a separate thread. Since the question you asked has been answered then you should mark the thread as solved. Then if you have another question about the same code you start a new thread with a title that explains the problem

NathanOliver 429 Veteran Poster Featured Poster

Do you have an array of objects that you are storing into that one file and then trying to read it back?

NathanOliver 429 Veteran Poster Featured Poster

Try this

void travels :: display_data() 
{
    ifstream Ifile;
    Ifile.open("CUSTFILE.DAT");
    Ifile >> customername >> no_of_people >> package_category >> cost >> date;
    cout << customername << " " << no_of_people << " " << package_category << " " << cost << " " << date;
}
NathanOliver 429 Veteran Poster Featured Poster

I would also be interested in seeing your completed code just to compare with what I did with your code. If not I understand.

NathanOliver 429 Veteran Poster Featured Poster

You don't and what he entered will not work since all of your members are not strings.

NathanOliver 429 Veteran Poster Featured Poster

The ios::binary flag might be interfering with outputing a string. Also you don't need a while loop since there is only one set of data. I would just get rid of the while loop for now.

NathanOliver 429 Veteran Poster Featured Poster

Write and read are defined as taking a char * as there first paramater and the amount of bytes to read as the second paramater. Because it use a char pointer we can effectivly cast any type of data we want as long as we get the size. So if you want to write an entire class to a file you caan use write and read as how I showed in my previous post. This does not work with dynamic contianers like a string or a vectore since there sixe can change. You need to add an extra step in these cases. Were you able to get your values from the file using my first method?

NathanOliver 429 Veteran Poster Featured Poster

The problem is that you are reading the data into one variable. You need to read in the variables how you outputed then.

Ifile >> customername >> no_of_people >> package_catagory >> ...

You can also write and read the entier class since you are using binary output like

Ofile.write((char*) this, sizeof this);  // this writes the whole class
Ifile.read((char*) this, sizeof this);  // this reads the whole class
NathanOliver 429 Veteran Poster Featured Poster

generally if you want the node to hold multiple pieces of data then you should create a class or struct that would hold all of that data and then have the node in the linked list point to a instance of that object.

class Foo
{
    int a,b,c,d;
};

int main()
{
    List<Foo*> bar;
    Foo * one, *two;
    bar.insert(one);
    bar.insert(two);
}
NathanOliver 429 Veteran Poster Featured Poster

are you trying to write the class to a file and then read it back?

NathanOliver 429 Veteran Poster Featured Poster

If it allows you to put it in a namespace theb you might ne able to make unlink a member function and then call the namespace function inside the member function.

int ClassName::unlink(const char* foo)
{
     return uinstd::unlink(foo);
}
NathanOliver 429 Veteran Poster Featured Poster

I'm not sure if this is legal to do but maybe

namspace unistd
{
    #include "unistd.h"
}

// later on
unistd::unlock();

If that doesn't work I'm not sure if it is possible but you could always change the name of your class function.

NathanOliver 429 Veteran Poster Featured Poster

is the unlink function in the library part of a namespace?

NathanOliver 429 Veteran Poster Featured Poster

Can you get rid of the unlink function in you class?

NathanOliver 429 Veteran Poster Featured Poster

could you re post the code you have now.

NathanOliver 429 Veteran Poster Featured Poster

you have shape declared in you circle constructor but you don't have circle derived from shape. also you do not have a destructor and you will need one since this class uses dynamic memory. You also have a bunch of methods defined but not declared. maybe this is because you are trying to inherit from the shape class?

NathanOliver 429 Veteran Poster Featured Poster

Yes you could have them stored in a text file and then have a vector in your sprite class to hold the data. Then if you need it you can read the data from the file and store it into the vector.

NathanOliver 429 Veteran Poster Featured Poster

I guess I forgot more math then I thought. A couple of years ago this would have been second nature. Oh well I guess I'll just have to buy some math books and relearn what I forgot. Thanks for the explanation.

NathanOliver 429 Veteran Poster Featured Poster

That's just it I don't know. Is this your code? If not where did it come from. To me it seems to be a macro someone created to assist in debugging.

NathanOliver 429 Veteran Poster Featured Poster

the problem is with your set1st function. you need to set the member variables to the inputted variables. Also it should be a void function.

void set1st(int x1, int y1, char z1)
        {
            x = x1;
            y = y1;
            z = z1;
            setBoard();
            board[y][x] = z;
            displayBoard();
        }

Then in your move function you don't need to pass the variables to it just use the member variables.

void moveup()
{
     if (y < 2)
     {
         set1st(x, y, 'X');
         return;
     }
     set1st(x, y - 1, 'X');
}

Also you should move the system("CLS"); to right after getch(t); in your move function. This should get you on your way.

NathanOliver 429 Veteran Poster Featured Poster

Looks like it could be a macro to display text only in debug mode.

NathanOliver 429 Veteran Poster Featured Poster

If you ever decide to release the source code I would love to take a look at it.