vijayan121 1,152 Posting Virtuoso

for standard C++ (ISO/IEC 1998,2003), the project type you would use is one of Win32 Console Application / Win32 library / General MakeFile Project. if you are new to Visual Studio 2005, start with a Win32 Console Application project. and in the project settings, disable microsoft language extensions. ( either /Za compiler switch or from the IDE, Menu -> Project -> Properties -> Configuration Properties -> C/C++ -> Language -> Disable Language Extentions = True )

vijayan121 1,152 Posting Virtuoso

the issuse is that your program is written in C++/CLI, the dll is in pure C++. to use the dll, you would need to use p-invoke. you could

#pragma unmanaged
#include <dll header files>
#pragma managed

you would also need to make modifications in your project settings (eg. change /clr:pure or /clr:safe compiler switch to just /clr), and perhaps a few changes in your code.
for more details, see:
http://msdn2.microsoft.com/en-us/library/ms973872.aspx
http://msdn2.microsoft.com/en-us/library/x0w2664k(VS.80).aspx

vijayan121 1,152 Posting Virtuoso

you could use the boost tokenizer library. here are a few links:
http://www.boost.org/libs/tokenizer/index.html
http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/tokenizer/examples.cpp

you could also use the boost string algorithms library (if the file is read line by line into a string)
http://www.boost.org/doc/html/string_algo.html

vijayan121 1,152 Posting Virtuoso

could i create a web server out of this socket server?

start by creating a server (handling http requests) which will handle only one request at a time. once that is working well, you can try scaling it up to handle many requests. here is a link you might find helpful:
http://www.codeproject.com/useritems/generic_pipeline_cpp.asp

vijayan121 1,152 Posting Virtuoso

what you wrote (sending hello world to a client) is a socket server; if you also handle http requests and provide http responses, you would have the rudiments of a web server.
for what a web server is, see:
http://en.wikipedia.org/wiki/Web_server
http://en.wikipedia.org/wiki/Apache_HTTP_Server

vijayan121 1,152 Posting Virtuoso

normally, you would not try to write a web server yourself. instead you would host your web application inside an application server like apache or IIS. and let that take care of not merely threading, but also a lot of other issues which need to be addressed (security, cookie management, crah recovery, process or thread pooling etc.)

vijayan121 1,152 Posting Virtuoso
#include <boost/lexical_cast.hpp>
int main( int argc, char* argv[] )
{
    if( argc> 2 )
    {
      try 
      {
        int value = boost::lexical_cast<int>( argv[2] ) ;
        // use value
      }
      catch( const boost::bad_lexical_cast& )
      {
        // cast error
      } 
}

this is part of the proposal for c++0x (in TR2) and is almost certainly going to be accepted. see: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html
so we might as well start using it.

vijayan121 1,152 Posting Virtuoso

What i expected is the result should be a floating point number but why it gives integer number ?
Please tell me actually what is happening .

stream output in c++ by default omits the decimal point if there are no significant digits after it. so,
cout << 64.0 << '\n' ; // prints just 64
cout << showpoint << 64.0 << '\n' ; // prints 64.000000

(the showpoint manipualator makes the stream insert a decimal point even when there are no significant digits after it.)

vijayan121 1,152 Posting Virtuoso

check the header DCPPPClasses.h for a missing ; at the end of the class, mismatched (), {} etc.
line 9: _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, 10 WORD, int, int); is an obvious error on many counts.

vijayan121 1,152 Posting Virtuoso

9/5 is an integer expression (==1). use
float fahrenheit = celsius * float(9)/5 + 32 ;
it would be better to use doubles instead of floats unless there is an externally imposed constraint.
salem, didn't see your post!

vijayan121 1,152 Posting Virtuoso
WolfPack commented: Nice links +8
vijayan121 1,152 Posting Virtuoso

also line 12: int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevi, 13 LPSTR szcmdline, int icmdshow)

vijayan121 1,152 Posting Virtuoso
vijayan121 1,152 Posting Virtuoso

line 4: LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT 5 message, WPARAM wParam, LPARAM lParam);
line 9: _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, 10 WORD, int, int);

these are the errors. the compiler/ide you are using seems to emit very poor error messages.

vijayan121 1,152 Posting Virtuoso

...You earn a rep point for your kindness.

i think that most people would pay no attention to rep points. in any case, you should not be adding to the reputation of someone who misreads your question.

vijayan121 1,152 Posting Virtuoso

i am sorry, i did not read your question carefully and misunderstood it. to do what you want, we would need to use either pointers to members or templates. at this stage, you should probably just unroll the loop in your code.

vijayan121 1,152 Posting Virtuoso

use an array. eg.

enum { MAX_STUDENTS = 16 };
Student students[MAX_STUDENTS] ;
for( int i=0 ; i<MAX_STUDENTS ; ++i )
{
  // ...
  cin >> students[i].first_name ;
  // etc.
}

you should also modify function print_student to take const string& args (not void*). passing by reference is as efficient as passing by pointer.

vijayan121 1,152 Posting Virtuoso

you need to have a user defined type for performing arithmetic operations (atleast a plus) on integers with large precision. either write a big_integer class or use a library
eg:class bigint from the LiDIA library (http://www.cdc.informatik.tu-darmstadt.de/TI/LiDIA/)

vijayan121 1,152 Posting Virtuoso

you could start by going through this tutorial
http://www.llnl.gov/computing/tutorials/pthreads/
and then attempting these exercises:
http://www.llnl.gov/computing/tutorials/pthreads/exercise.html

vijayan121 1,152 Posting Virtuoso
vijayan121 1,152 Posting Virtuoso
ps->first_name == (*ps).firstname ; // ok
MyClass& ref = *ps ; ref.first_name ; // ok
*(ps).first_name ; // error, equivalent to
*(ps.first_name) ; // error, ps is a pointer
// reason: operator precedence
vijayan121 1,152 Posting Virtuoso

Do you really think the only possible way to simulate queue behavior is by physically removing every item?

no i do not. i do think that keeping objects alive after their logical lifetime is over is not efficient. (how inefficient depends on the kind of object).

vijayan121 1,152 Posting Virtuoso

you can call functions inside the body of the constructor. colon initialization can be used only for initialization of members or base classes (using copy constructor semantics).

vijayan121 1,152 Posting Virtuoso

>a vector cannot be used as the container to be adapted for a std::queue;
>the container needs to support push_back and a pop_front.
Try reading for comprehension next time. That was an either/or statement. You can use the stack and queue adapters OR vector and deque because the adapters are notoriously inflexible in practice. Of course, you could play games with me about using stacks to simulate a queue and queues to simulate a stack if you want to try to recover from your mistake, but that would be reaching.

i'm not interested in playing games with you.

>using a vector to implement a queue would not be a good idea (performance).
You're not very creative, are you? Just because push_front and pop_front aren't available to a vector doesn't mean you can't achieve the correct functionality of a queue in an efficient manner.

here is what ISO/IEC 14882:1998(E) has to say:

23.2.4 - Template class vector [lib.vector]
-1- A vector is a kind of sequence that supports random access iterators. In addition, it supports (amortized) constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage management is handled automatically, though hints can be given to improve efficiency.
-2- A vector satisfies all of the requirements of a container and of a reversible container (given in two tables in lib.container.requirements) and of a sequence, including most of the optional sequence requirements (lib.sequence.reqmts). The exceptions are …

vijayan121 1,152 Posting Virtuoso
// ...
        base( int t ) : i(t) {} // initialize member i with t
       // ...
vijayan121 1,152 Posting Virtuoso

...NetBeans...That's for Java. An entirely different programming language.

see http://www.netbeans.org/products/cplusplus/
it is lighter on resources than eclipse+cdt, and would be a good option for a c++ IDE, particularly on a unix/linux platform.

John A commented: Ah, thanks. +13
vijayan121 1,152 Posting Virtuoso

the stanard libary <stack> and <queue> are just container adapters, eg.

template< typename T, typename CNTR = std::deque<T> >
          struct queue ;

they just adapt an implementation of a sequence container to provide the interface required for a stack/queue.

...You can also use a vector or deque as both a stack and a queue...

a vector cannot be used as the container to be adapted for a std::queue; the container needs to support push_back and a pop_front. using a vector to implement a queue would not be a good idea (performance).

vijayan121 1,152 Posting Virtuoso

the dereference operator (*) on a pointer gives a reference to what is pointed to. the address of operator on a reference gives a pointer to what is being referred to. since a reference to a function can be implicitly treated as a pointer (an implicit address of is assumed),
*f == *(&f) == f

it really has got nothing to do with values or data. a void* points to some data (we do not know what it's type is), but cannot be dereferenced. an int* points to an int, so dereferencing it gives us a reference to an int (int&).

vijayan121 1,152 Posting Virtuoso

you are using a 16 bit compiler. which one?

vijayan121 1,152 Posting Virtuoso

you are probably trying to enter a name that has embedded (white) spaces. to read an entire line (may contain white spaces) use getline.
getline( cin, employee ) ;

vijayan121 1,152 Posting Virtuoso

you also need to

a. remove your handler for OnPaint()
b. use the device context that is passed as an arg to OnDraw

  ... :: OnDraw( CDC* pDC )
 {
       pDC->whatever ...
 }
vijayan121 1,152 Posting Virtuoso

... I still vote for Python or Java.

glad to note that you dropped perl from the list. a 'write once, read never' language is probably not good for anyone.
smalltalk would rank very high among good languages for beginners; it is arguably the best language for beginners.

vijayan121 1,152 Posting Virtuoso

>
> << (Cat::HowManyCats == 1 ? "is " : "are "
While this seems like a good idea, it really makes it much harder to translate into other natural languages, which do not have such simplistic rules for plurality.

true. and it does not resolve between " cats alive!" / " cat alive!". it is not all that simplistic even in english; a general solution is not an easy one (cat/cats, child/children etc.). perhaps the easy way out is something like
number of cats: 23 (or 0 or 1).

vijayan121 1,152 Posting Virtuoso

you need to use a CPaintDC (not a CClientDC) in a handler for OnPaint (WM_PAINT requires calls to BeginPaint/EndPaint). it would be much better (and easier) if you override the virtual function CView::OnDraw( CDC* ) and write your code for painting the view there (and not implement OnPaint yourself). let the framework do all the work including creating the right device context and then call your override for OnDraw.

vijayan121 1,152 Posting Virtuoso
int howManyCatsFunction()
{
     cout << "there " << (Cat::HowManyCats == 1 ? "is " : "are " )
          << Cat::HowManyCats << " cats alive!" << endl;
}

you also need to write a copy constructor which increments Cat::HowManyCats to get the right number always.

vijayan121 1,152 Posting Virtuoso

Why this is legal?
(****bar)() ;

void bar() { /* ...  */ }

int main()
{
  void (*pfn)() = bar ; // ok, bar is treated as &bar
  void (&rfn)() = *pfn ; // ok, *pfn is a reference to the function
  pfn = rfn ; // ok, equivalent to pfn = &rfn ;
  pfn = *bar ; // ok, equivalent to pfn = &*&bar ;
  pfn = **bar ; // ok, equivalent to pfn = &*&*&bar ;
  pfn = ***bar ; // ok, equivalent to pfn = &*&*&*&bar ;
  (*pfn)() ; // ok, call bar
  (****bar)() ; // ok, equivalent to (*pfn)() ;
}
~s.o.s~ commented: Nice. +19
vijayan121 1,152 Posting Virtuoso

...c++ takes function name as an address of it...

c++ takes the name of the function (as an expression) to be either a reference to the function or a pointer to the function. eg.

#include <iostream>

void foo( void(*pfn)() ) { std::cout << "pointer\n" ; }
void foo( void(&rfn)() ) { std::cout << "reference\n" ; }
void bar() { std::cout << "bar\n" ; }

int main()
{
  bar() ;  // ok
  (*bar)() ; // ok , bar == &bar,  so  (*bar) == bar
  (**bar)() ; // also ok
  (***bar)() ;  // also ok

  foo(bar) ;  // error - ambiguous is bar a reference or a pointer?
}
vijayan121 1,152 Posting Virtuoso

if you are using the current version of platform sdk:
header is winsock2.h
import library (link to) ws2_32.lib
shared library (dll) ws2_32.dll

vijayan121 1,152 Posting Virtuoso
private: System::Void button1_Click( System::Object^ sender,
                                                       System::EventArgs^ e) 
{
  textBox1->Text = ( (int^)randNumGen->Next(0,41) )->ToString();
}

this will only work with clr 2.0 or later (requires implicit boxing).
(alternatively, you could use the compiler option oldSyntax)

vijayan121 1,152 Posting Virtuoso
private: System::Void button1_Click( System::Object^ sender,
                                                       System::EventArgs^ e) 
{
  textBox1->Text = __box( randNumGen->Next(0,41) )->ToString();
}
vijayan121 1,152 Posting Virtuoso

another question, is it possible to store and array in a vector?
eg an a array of tests

not directly (C arrays do not have value semantics).
however, you could simulate value semantics by wrapping the array in a structure. eg.

template< typename T, size_t N > struct array
{
  T& operator[] ( size_t pos ) { return a[pos] ; }
  const T& operator[] ( size_t pos ) const { return a[pos] ; }
  T a[N] ;
};
std::vector< array<double,50> > container ;
vijayan121 1,152 Posting Virtuoso
// .....
  else {
       Student S;
       char c;
     while(!infile.eof()) {
        infile >> S.StudID;
        infile.get(c);
        infile >> S.StudMark;
        infile.get(c);

        clientRequest.push_back( S );
        
      infile.get(c);   
     } //end while
// .....
vijayan121 1,152 Posting Virtuoso

The reason I have to give this a fixed size, is becuase I have to map this in shared memory...

just placing the map in shared memory is insufficient; you would need to
a. write a custom allocator (compatible with std::allocator) that can (sub)allocate from the shared memory region for the map.
b. place the map itself in shared memory. requires sizeof( map<int,int,custom_alloator>)
c. ensure that the shared memory is mapped at the same virtual address in every process that uses it (allocators return absolute pointers).
d. you would also need to synchronize access to the map.

it would probably be better to just create a fixed size array of structures (key,value) sorted on the key and do a binary search.
ie. assuming that the keys are not very volatile.

vijayan121 1,152 Posting Virtuoso

this would probably be more readable.
and as efficient with a decent compiler.

struct client 
{
      explicit inline client( int a, int b, const std::string& n ) 
                                 : aa(a), bb(b), name(n) {}
      int aa;
      int bb;
      std::string name ;
};

extern std::vector<client> vec ;
extern std::istream file ;
int a, b ; std::string name ;
file >> a >> b >> name ;
vec.push_back( client(a,b,name) ) ;
vijayan121 1,152 Posting Virtuoso

if you just want the sum, this would be simpler:

int sum2(string line) 
{
  istringstream stm(line) ;
  string  x ; stm >> x >> x ;
  int sum=0 ;  int n = 0 ;
  while( stm >> n )  sum += n ;
  return sum ;
}
vijayan121 1,152 Posting Virtuoso

>This will work in C++ wht abt c?
No, it won't work in either because you can't call a function at global scope....

calling a function at global scope is certainly possible in C++. dynamic initialization of statics at global scope is supported; here caling printf to initialize a global integer is no different from calling the constructor to initialize std::cout.

if you cannot use formatted output functions like printf, fprintf etc., an fwrite (unformatted output) is a possibility. fwrite returns a size_t, so you can still use it for dynamic initialization of a global int.

vijayan121 1,152 Posting Virtuoso

That gave the same error as before. Does it have something to do with how I got scores? And I would rather not use boost.

i just tested the code (which i posted). compiles in both vc++ 8.0 and gcc 3.4.6. also works correctly in both.

vijayan121 1,152 Posting Virtuoso
ostringstream stm ;
stm << "Total points " << points ;
MessageBox(hwnd, "You have bla bla", stm.str().c_str(), MB_OK);
vijayan121 1,152 Posting Virtuoso

convert a string to int this way.

string test = "1234" ;
  istringstream stm(test);
  int num = 0;
  stm >> num ;

  // if using boost (boost lexical cast), it is easier
  num = boost::lexical_cast<int>(test) ;
vijayan121 1,152 Posting Virtuoso
string process_line(string line)
{
  string first;
  string last;
  istringstream stm(line);
  stm >> last >> first ;
  string ret_val = last + string(16, ' ').substr(last.size()) + first ;
  for (int i = 0; i<10; ++i )
  {
    string score = "0" ;
    stm >> score ;  // if stm.eof() is true, score remains an unchanged "0" !
    ret_val += " " + score;
  }
  return ret_val ;
}