Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm sure the OP will thank you for doing his homework for him, even though it's not 100% correct. But I'll give you a B+ for good effort.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. Turbo C is a C compiler, not c++. Get a modern c/c++ compiler such as Code::Blocks or VC++ 2010 Express, both are free.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It compiled perfectly ok for me using vc++ 2010 express. Note that MyVector is in MyClass.h, not in MyClass.cxx. You still have the same error because you failed to move it.

MyDerivedClass.cx

#include <vector>
#include "MyDerivedClass.h"


void MyDerivedClass::DoSomething()
{
  this->vecPtr->v.push_back(1); //"invalid use of incomplete type 'struct MyVector'
}

MyClass.cxx

#include <vector>
#include "MyClass.h"


MyClass::MyClass()
{
  this->vecPtr = new MyVector;
}

MyClass::~MyClass()
{
  delete this->vecPtr;
}

MyClass.h

#ifndef myclass_h
#define myclass_h

struct MyVector
{
  std::vector<double> v;
};


class MyClass
{
  public:
    MyClass();
    ~MyClass();

    MyVector* vecPtr;
};

#endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That will work too except that <vector> must be include in the *.cpp/*.cxx files before any of the other header files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Then include it in each of the *.cpp or *.cxx files. And put it before myclass.h so that vector has been defined.

#include <vector>
#include "MyDerivedClass.h"
// rest of code here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you put the declaration of MyVector in MyClass.cxx it is not known to MyDerivedClass.cxx, therefore causing the error you got.

Move the declaration of MyVector from MyClass.cxx into the header file MyClass.h and include <vector> in that file too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to include <vector> in MyDerivedClass.cxx because its not included in any of the header files you created.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The C and C++ standards dictate how compilers do things. And the standards say that main() must return an integer value to the operating system. That always happens even in you decide to declare main() return void or even something else such as char*.

One reason for that is to let the operating system and possibly other programs know the exit status of the program. Its customary for return value of 0 to indicate that the program is exiting normally. Any other value would indicate some sort of error condition.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The double star means that it is a two-dimensional array, that is, its an array of pointers to strings. Each line in the file occupies one of the pointers in that array.

unsigned char ** C1dArray::get1dArray()
{
    unsigned char** pArray = 0;
    unsigned char tempbuf[40] = {0};
    int size = 0;
    ifstream in("filename.txt"); // open the file in text mode
    if( in.is_open() )
    {
      while( in >> tempbuf )
      {
         pArray = realloc(pAray, (size+1) * sizeof(unsigned char *));
         pArray[size] = strdup(tempbuf);
         ++size;
      }
    }
    return pArray;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There doesn't appear to be an option to add that button. I just use Ctrl+F5 which is nearly as easy as that button. You will find lots of differences between those two compilers. That button is probably the least one to be concerned about.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>is this the right way to do append ofstream?
No. Delete line 5 because line 4 opens the file in append mode. Its not writing to the file because of line 5.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>img = new unsigned char *;
How is img declared? If its unsigned char* img; then the above line is incorrect. Remove the * from that line.

This works ok for me

#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;

int main()
{
    unsigned char* buf = 0;
    vector<int> vArray;
    ifstream in("textFile1.txt", ios::binary);
    if( in.is_open() )
    {
        in.seekg(0, ios::end);
        int sz = (int)in.tellg();
        in.seekg(0,ios::beg);
        buf = new unsigned char[sz+1];
        in.read((char *)buf, sz);
        buf[sz-1] = 0;
        cout << buf << '\n';
        stringstream str;
        str << buf;
        int n;
        while( str >> n)
            vArray.push_back(n);
        in.close();
        cout << "vArray.size() = " << vArray.size() << '\n';
        for(size_t i = 0; i < vArray.size(); i++)
            cout << vArray[i] << '\n';

    }

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put that code from the DLL into the function that actually reads the file and see if it works.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why is DLL_Cubic() a void function? It doesn't do a thing with the array of ints after it is created.

What makes you think that the vector is not populated correctly? Your program isn't printing out the contentents so how would you know one way or the other?

You have to be careful about allocating memory in a DLL. Memory allocated in a DLL must be also destroyed in the same DLL. And likewise memory allocated in the main application program must also be destroyed in the program. Memory allocated in DLL can not be destroyed (deallocated) by the application program and vise versa.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post your program and text file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Would "sizeof int" solve the problem some ho
No. And neither will typecasting.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@Mike: All that loop you posted will do is store each digit of the character array in an element of the int array. That isn't what he wants. Each integer in the character array has to be converted from ascii representation to int and the result stored in an array.

There are at least two ways to do it

  1. I already posted one method using stringstream and will not repeat it.
  2. Something like what Mike posted but use atol() or strtol() to convert from ascii to int.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Dev-C++ is very old and outdated, and used an old version of gcc compiler. Replace it with Code::Blocks/MinGW and you will have few problems.

NicAx64 commented: I just moved to the CodeLite right now! Bye bye Dev-Cpp. and mingw 4.4 is faster that I thaught. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

did you include <sstring> ?

>>? ", " : " }\n");
Split that out into an if statement and see what the compiler says about it.

stream << matrix(x, y);
if( x < 3 )
   stream << ", ";
else
   stream << " )\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

as I said before you can use streamstring class to do that

#include <sstream>
...
int main()
{
   vector<int> nums;
   int n;
   unsigned char buf[] = "12 23 45 67 -12"; // read from a file
   stringstream str;
   str << buf; 
   while( str >> n )
      nums.push_back(n);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To read it directly into an int array

#include <vector>
#include <fstream>
using std::vector;
using std::ifstream;

int main()
{
   vector<int> ay;
   ifstream in("file.txt");
   if( in.is_open() )
   {
     int n;
     while( in >> n )
        ay.push_back(n);
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will have to post some of the contents of the file before we can tell you how to convert it. If its somethng like this:

123
456
789
10
20

You can use std::stringstream class to convert it from unsigned char* to an int array after its been read into one huge buffer. Or you could read it directly into the int array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have a custom user title too, because it's true that after 25+ years I'm still learning :) And I didn't like the default title -- too boastful.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Change the language of your computer to something like Chinese where they read right to left.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's called redirecting stdout to a file. Output to the screen is done with either stdout or stderr (in both C and C++).

Another way to do it is for program 2 to create a pipe through which program 1's stdout is redirected through the pipe to program 2. Here is an example in C language. I don't know if it can be used with c++ fstream class or not because I've never tried it.

NicAx64 commented: Thanks for the example, learn something keep up good work. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

@Adak: That's exactly how I do it too, even in physical disk files. There is really no point in rewriting an entire file to delete one record. Just mark it as deleted and write the program smart enough to recognize that. Its also the same thing that DBase did it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The class destructor is responsible for deallocating memory for those pointers, assuming the memory was allocated using new or malloc().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't really delete an element. All you can do is move the data in higher subscripts to lower ones. For example if you have an array of 10 elements and you want to delete the 2nd one you have to move elements 3 to 10 to elements 2 to 9. That leaves the 10th elemenet unused. It can not be deleted unless you allocated the array with malloc() then use realloc() to make the array smaller.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Too bad for you. And too late as well because I don't need you to work for me now. Pitty.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First figure out how to solve it on paper, then write a program to do it similar way.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>tmp += 2;
The first one doesn't work because the program keeps changing the value of temp on every loop iteration. Delete that line and the program will work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>let these extra things be discussed later

Nope. You get it after you do the work. Highland, Illnois, USA. Or, deposit $1,000.00 in my paypal account within the next 30 minutes.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And have a hand extend out of the monitor and slap him silly. I've seen an avatar something like that but don't remember whose it was.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, got it done and tested. But be warned that if I give it to you your teacher will know that you didn't write it and you will probably fail the course.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i will be very thankfull to you if you can post the complete source code which can be executed..


I will do your homework for you if you come over to where I work and work 8 hours for me at WalMart store.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you live in US you might remember John Cameron Swayze and his Timex commercials during the early 1970s. He did a lot of different Timex commercials and I only recall one time when the watch failed to pass the test.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>more than 70% of the universities here in UK have their plagiarism defined as the statement posted above.


So if someone asked you what color to paint s house, and you told him brown, the university would call that plagurism even though you painted that house yourself? Odd.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use a vector

vector<Point> points;
Point p;
while( inFile >> p.x >> p.y )
{
   points.push_back(p);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 66 of the code you posted: variable size has not been declared

line 77: what is Start ?

line 78: you need to use == boolean operator, not = assignment operator

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean like these?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A little pseudocode

beginning of loop
   display "Enter your password\n";
   get user keyboard input
   if password is correct then exit this loop
   if this is the third attempt then exit this program,
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When a line of text is read from the file check to see if it contains "fr_name". If it does, then extract the name and put it into the vector. std::vector<std::string> friends;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What compiler are you using? Your program compiles without error using vc++ 2010 express. And this is the output

3.1400Press any key to continue . . .

Note that if you want a line feed before Press then you need to add '\n' to the cout statement.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

access the file with what? If you want to read the data back then just open the ifstream for input and call its read() method.

If you mean how to read the file with another program like Notepad.exe -- they can't.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Does anybody know how I could do this?

Yes -- write a probram using VB.NET. If you want a more complete answer you will have to post your question in one of the software support forums, not here in Geek's Lounge.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean you want to call notepad.exe from your *.cpp program? Then use system() or ShellExecute().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The thread was started Oct 18, 2002. I have no idea who alice is because I didn't join DaniWeb until 2005.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Microsoft name mangling is a very complex topic. After a littled testing of the code in the original post to this thread I've come to the conclusion that Microsoft does include the return type as part of the mangled name. The compiler allows both versions of the function because names are mangled at compile time, not link time. Since the two classes are in two different *.cpp files the compiler has no way of knowing that the two functions differ only by return type. If you put both functions in the same *.cpp file the compiler generates the error message error C2556: 'void A::printText(void)' : overloaded function differs only by return type from 'int A::printText(void) .

To further complicate things, add a contructor to each version of the class and print out a different message in each constructor. Only one of the two contructors is called for both clA and clB objects.