jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oops, this may be out of date due to overlap...

No worries, I'm bound to have overlooked something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

They are called at the time the object is created. They can be used to initialize member variables and/or allocate memory for them.

class MyClass
{
   private:
       int x,y;
   public:
       MyClass(int xin,int yin)
       {
            x = xin;
            y = yin; //there's a shortcut to doing this, look up initialization lists
       }

       MyClass()  //default constructor (no parameter)
       {
           x = 0;
           y = 0;
       }

      ~MyClass() //destructor
       {
             //nothing brewing here
       }

};
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if i would've known the answer, i wouldn't had started the thread......

Me telling you the answer doesn't help you learn anything. I'm just asking you some follow up questions, I'm not expecting that you're going to know everything

If you include a destructor with nothing in the body of it (or when the compiler provides a default constructor), it doesn't do anything at all.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not when the program is started, but when the object is created.

How about the destructor for a class that doesn't do any memory allocation?

What happens when you don't specify a constructor for the class?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are some of your thoughts, then someone can either confirm them or make corrections.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't have any experience with vtk. Some people that are around might, but I can't remember who they are. I haven't done anything in the way of animation either, so I can't help you with that either. Let the question hang around for a bit and see what the other replies will be.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since you're not asking about C++ explicity, do you have access to Matlab? There is a command called quiver3 that might be exactly what you are seeking (http://www.mathworks.com/help/techdoc/ref/quiver3.html). It looks like octave might have something similar as an add on (http://octave.sourceforge.net/octave/function/quiver3.html).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 61 do a strcpy instead to move it into the buffer. Right now you're concatenating a good string onto junk. Then concat onto the newly copied string.

It looks like strcat_s takes a size parameter like strcpy_s does, so did you use it with 3 arguments?

Also, since you're going to run into it anyway, look at the order in which you are adding the strings in 61 and 63. So, you'll want to strcpy the first one and strcat the second one.

L3gacy commented: thanks +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please post your current code with the changes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try out the Mark Summerfield free one (http://www.qtrac.eu/marksummerfield.html, Qt4 version, first edition). It's not bad. The first few chapters he takes you through creating a "spreadsheet" application. That part may be too basic for your needs, but he then goes through the rest of the library (including all of the threads and sockets info). Again, it's probably one that didn't receive super high marks, but it's a good jumping off point, IMO.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

hi
i think you have overloaded ">>" operator so that compiler gets confused about which operator should be matched exactly with that operand since >> is a built in operator so you should not overload it.
Hope this will clear your confusion...

Wait, what?

The issue is that your prototype for >> in your class declaration doesn't match what you have in your defintion.

friend istream& operator>>(istream& is, Rational[B]&[/B] r);

vs.

istream& operator>>(istream& is, Rational r)

To the compiler, those are two different signatures, one with a reference to a Rational and the other without. Just change the second to Rational & r Also, a minor point, the semicolons after your method definitions 46,52,58, etc., are extraneous (when compiled with a low warning level, they are passable, but conventionally they are not placed there).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You want a function like strcat instead of strcpy in that case (the M$ "safe" equivalent is http://msdn.microsoft.com/en-us/library/d45bbxx4(v=vs.80).aspx strcat_s.
strcpy by nature just clobbers whatever is there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Easy there, I don't think anyone was putting the language down at all. I was just offering you a suggestion based on where people have posted questions about it in the past.

I understand what you mean about all of the C "family" being unique languages.

I don't speak for the site in any way shape or form, so I'll defer to Dani for the rest of the discussion.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@OP I think they've only been answered occasionally, but people have posted Obj-C questions in both C and C++. So, there are higher traffic forums, besides MD, for posts about that topic.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

what variables am i going to plus and minus?

If you are sorting, you are not adding or subtracting anything. Sort your array in place. Here's one pass through the data(sorting in ascending order):

|6|3|5|9|2|
is 6 > 3, yes, so swap those elements
|3|6|5|9|2|
is 6 > 5, yes, so swap those elements
|3|5|6|9|2|
is 6 > 9 no, so leave the element alone
|3|5|6|9|2|
is 9 > 2 yes, so swap those elements
|3|5|6|2|9|

Since we know that element0 is going to be sorted with respect to element1, start at element1 and repeat the above process. As we go over the list iteration after iteration, that 2 will percolate down to the bottom. That site I gave you is great because it shows you animations. See if you can make some C code out of the pseudocode they provide there along with the details above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh, I didn't even notice that before (sorry), you don't need to make those handles to int32s (System::Int32^), you can just make them ints.

Did you experiment with the lists at all.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at http://www.sorting-algorithms.com/bubble-sort for the most basic type of sort

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there a question in there somewhere?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

May I make a suggestion? Seeing as how this is getting to be painful with the arrays, try using a List<String^> instead. It's a lot more intuitive. It's under the System::Collections::Generics namespace. You can index in, but you can also just use the add method to tack the next string onto the end.

Also, rather than going through a lot of if statements like you have in your last code snippet, make a list (or array lol) of textBoxes and a List of comboBoxes, that way you can use a loop over everything.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need the array to be static if you do it this way. What line is that Error 1 pointing to?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, you want to open it using ifstream, but since your compiler is pre-standard it may not have that method of the class (I seem to remember this from another poster at one point).

What will probably work (and is also used) is to test that the ifstream object is not null:

ifstream ifs("myfile.txt");
if(!ifs)
   //file didn't open for whatever reason
anu07 commented: worked :) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I tried the following program:
testme.h

#pragma once

ref class testme
{
    public:
        testme(void);
        static cli::array<System::String ^>^ strar = gcnew cli::array<System::String^>(20);
};

Arraytest2.cpp

// ArrayTest2.cpp : main project file.

#include "stdafx.h"
#include "testme.h"
using namespace System;

int main(array<System::String ^> ^args)
{
    testme tm;
    tm.strar[0] = "Test";
    tm.strar[1] = "Me";
    
    
    return 0;
}

(I didn't make a Winforms app, but it's essentially what you are asking it to do)
So, I'm not exactly sure what that error message is directed at. Do you try to give it an i > 19?

I still say the best thing to do is put

cli::array<String^>^ salka;  where you had it, and add

salka = cli::array<String^>(20); to your form's constructor
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're going to instantiate your array outside of one of the methods (Load, Click, etc.) it must be static. The constructor of the form is a good place to instantiate it, but leave the declaration of it right where it is.

I've heard (though I've yet to get my hands on a copy) that Ivor Horton's book has a good treatment on C++/CLI. Yes, it is a pain in the ass. It was originally meant as a connector between C++ and .NET, but I think it evolved into something that some people use for its own sake. FunctionX has one of the better tutorials for it, but it's getting outdated.

My impression (but don't quote me on it, I'm not an expert, I just find the C++/CLI dialect interesting) is that one of M$'s evil plans is to get people to use C# for their UI (and other coding) with native C++ DLLs where necessary and C++/CLI filling in any middle ground.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There may be some non-standard functions to do so in TC++, but I would just try to open it using an fstream object then use the .is_open() method to make sure that it has opened successfully. That's kind of quick and dirty, as I'm sure there are different OS dependent ways to do that, so someone should definitely correct me if I'm off base.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

comboBox1->SelectedIndex will give you the zero-based index of the item you've selected. Probably you were just in a rush, but you want the == instead of = in your line of code above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Won't strcpy() copy the address of the first letter of the string to the hobby pointer,

The compiler knows that hobby is a pointer, but there's no space allocated, so it's not pointing to anything.

strcpy won't keep adding on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You robbed him of that fun!! Only kidding.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a debugger (or pepper it with cout statements) to see how far it gets in execution. If you can't find it after that, post back and I'll compile it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

LOL because you wanted an array of strings.

std::string strarr[2];
strarr[0] = "hello"; //first string of the array
strarr[1] = "world"; //second string of the array
strarr[0][0] is 'h'
strarr[1][0] is 'w'
strarr[0][4] is 'o'

Just like if

std::string str1 = "hello";
str1[0]  is 'h'
str1[4] is 'o'

You have to index into the string you want in the array, and then index into that string to get the character you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't use gcount in your loop, use str[0].length(). Turn your if/else construct into

if(it is A-M or a-m)
    add
    print
else if(it is N-Z or n-z)
    subtract
    print
else
    Print it out

The way you have it, it's too confusing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

17 and 24, you're not getting the character, you're trying to do that to a whole string. Formulate it like you do in the if statement str[0][i] This is why having an array of strings is a bit confusing, as you're only using the first one anyway...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the error? Post up your changes to the code with -13.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So since you are using the string array, line 8 will have to look something like str[0][i] >='A' && str[0][i]<='M' since you want to compare characters. That's the ith character of the first string in your array. You also need && instead, since your values will be over that interval.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post what you are trying to compile currently.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Mixing cin and getline like you do can cause problems. Since you press enter after entering in userInputString and cin does not take up that resulting '\n', it stays in the stream and gets taken up by the getline (and interpreted as the end of the input, so control appears to "skip" over it).

See the sticky thread in this forum about flushing the input stream for more details. However, in this case, with one stray '\n' it is probably sufficient to put a cin.ignore(); before your getline statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit above. It's all good, it's just confusing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

my input is dependent of what Plaintext.txt

Right, but do you really need 100 strings of indeterminant length to do so? I think you're confusing std::strings and C-strings.

0x41 is a memory location

Maybe what you are doing makes sense to you, but it doesn't make any sense to me. 0x41 is not a memory location, it is the hexadecimal equivalent to the integer which defines the letter 'A' in ASCII.

std::string mystr= "hello";
for (int i = 0;i<mystr.length();i++)
   if(mystr[i] > 0x41 && mystr[i]<0x4d)
        mystr[i] +=0x0D //character values, not the pointer value
   else
        etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you are confused, string str[100] is giving you an array of 100 std::strings. Is that what you want?

Bear in mind that characters are just 1-byte ints, so they can be added to or subtracted from:

char c = 'a';
c++;
std::cout<<c<<std::endl; //'b'
c+=2;
std::cout<<c<<std::endl;//'d'

Bearing also in mind that the elements of the string can be accessed by index:

std::string animal= "cat";
std::cout<<animal[0]<<std::endl; //'c'

(note that this is different from the array of strings that you had before where
str[0] would give you the first string and str[0][0] would give you the first character of the first string).

See if that gets you going in the right direction and post back with any difficulties.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If he wants to learn he will

He won't if he just copies your code verbatim.

the fact that you got some power to affect someones reputation

That doesn't matter. Even if I had zero rep power, I would still give you the comments (it also helps others to be aware of what you're up to).

Boys with sticks ..

You're the one that needs to grow up and learn to be a part of a community.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh jeez. Yes! Class members are private by default. Thanks hag++ for having sharper eyes!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm smart enough to know that!

Wasn't insinuating anything less, lol. It was just that you had said

this simple method call

Are you including the header file or whatnot for class cmd in the file in which you have placed the first two code snippets?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If something is unclear you are welcome to ask.

Yes, why do you keep giving complete, compilable, cookie cutter solutions that the OP can simply turn in for a grade even thought you have been asked more than repeatedly not to do this?

jon.kiparsky commented: Keep hammering on this, it's worth the effort. +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Write a main program that reads in a series of product code

Ah, okay. So all of your input (loops included) should be in main, then. Try implementing the string validation part and post back if you have trouble.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take in product code as a string rather than an integer, and then verify that all of the characters in the string are digits.

Just as an aside, why are you passing in the value for product code into the function if you're just going to ask the user to input it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need two DateTime objects, not two DateTime handles (using the ^)

DateTime dt1 = DateTime::Now;
DateTime dt2 = DateTime::Now;

int diff = DateTime::Compare(dt1,dt2);

but again, you can use if(dt1 < dt2)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

dynCurrentTime->Now is a handle to a DateTime object? (DateTime ^) or?

If not, I would just declare a regular DateTime object:

DateTime time1,time2;
time1=dynCurrentTime->Now;
etc.

Then you can use the overloaded < > == operators.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm getting a bit confused because it sounds like part of the time you are having problems once you've entered the command and it sometimes sounds like you can't compile the project. You also gave an example program that in no way represented what was really going on...that's forgiven, but it's good to know the whole story.

You also say that this program is being started by another program. Is it possible there's a problem with the other program? If you have to, for the time being, write out the path into a text file and read that into this program to get the filename.

Edit: I had failed to connect you were the one doing .net stuff in your other program, sorry, lol

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If base is a method call it would have to look something like print.base("print"); You can't set a method equal to a string like that (only a member variable named base), and you need the () when calling a method. If this still doesn't solve the problem, post the class definition for cmd.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Show the line where you instantiate print.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't have SDL so I can't compile it readily.

Try putting the argument in quotes and/or eliminating the double backslashes -- you should only need those when writing strings in your code, not when entering them in.