Re: Visual C++ Language 'std' : does not exist or is not a namespace
Geo Babu
this is the view of my code...
if "iostream" is not included...this program must give an error. but its ok. the only problem is with the part ie high lighted by green color. In normal way cout want to be compile with out no error. but here its giving errors.
#include<iostream.h>
#include "stdafx.h"
#include "serial.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//using namespace std;
HANDLE hCommPort = INVALID_HANDLE_VALUE;
void CSerial::ConfigPort()
{
hCommPort = CreateFile (TEXT("COM1:"),
GENERIC_READ,
0, // COM port cannot be shared
NULL, // Security attributes
OPEN_EXISTING,
0, // Non-overlapped operation only
NULL); // Templates are not supported
if(hCommPort == INVALID_HANDLE_VALUE)
{
ReportCommError(TEXT("Opening Comms Port."));
return;
}
// set the timeouts to specify the behavior of
// reads and writes.
COMMTIMEOUTS ct;
ct.ReadIntervalTimeout = MAXDWORD;
ct.ReadTotalTimeoutMultiplier = 0;
ct.ReadTotalTimeoutConstant = 0;
ct.WriteTotalTimeoutMultiplier = 10;
ct.WriteTotalTimeoutConstant = 1000;
if(!SetCommTimeouts(hCommPort, &ct))
{
ReportCommError(TEXT("Setting comm. timeouts."));
ClosePort(); // close comm port
return;
}
// Get the current communications parameters,
// and configure baud rate
DCB dcb;
dcb.DCBlength = sizeof(DCB);
if(!GetCommState(hCommPort, &dcb))
{
ReportCommError(TEXT("Getting Comms. State."));
ClosePort(); // close comm port
return;
}
dcb.BaudRate = CBR_19200; // set baud rate to 19,200
dcb.fOutxCtsFlow = TRUE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fOutxDsrFlow = FALSE;
dcb.fOutX = FALSE; // no XON/XOFF control
dcb.fInX = FALSE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if(!SetCommState(hCommPort, &dcb))
{
ReportCommError(TEXT("Setting Comms. State."));
ClosePort(); // close comm port
return;
}
// now need to create the thread that will
// be reading the comms port
/*HANDLE hCommReadThread = CreateThread(NULL, 0,
CommReadThreadFunc, NULL, 0, NULL);
if(hCommReadThread == NULL)
{
ReportCommError(_T("Creating Thread."));
ClosePort(); // close comm port
return;
}
else
CloseHandle(hCommReadThread);*/
}
void CSerial::ReportCommError(LPTSTR lpszMessage)
{
TCHAR szBuffer[200];
wsprintf(szBuffer,
_T("Communications Error %d \r\n%s"),
GetLastError(),
lpszMessage);
//cout<< szBuffer << endl;
}
void CSerial::ClosePort()
{
if(hCommPort != INVALID_HANDLE_VALUE)
{
CloseHandle(hCommPort);
hCommPort = INVALID_HANDLE_VALUE;
//cout<< _T("Com. port closed")<<endl;
}
// else
//cout<< _T("Com. port was not open")<<endl;
}