Geo Babu

hi,

i am writing a program containing serial port communication , for a customized hand held device, with the help of embedded VC++ 3.0. while compiling the module for the serial port , i am getting the following errors.

error C2871: 'std' : does not exist or is not a namespace
error C2065: 'cout' : undeclared identifier
error C2297: '<<' : illegal, right operand has type 'unsigned short [200]'

my code contains the following lines...

#include<iostream>
#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()
{
.....
...
cout<< _T("Com. port closed")<<endl;
....
....
kindly help me to solve this problem.

thank you
Geo Babu


Re: Visual C++ Language 'std' : does not exist or is not a namespace

_johnr_

Hi Geo,

If you're using precompiled headers the compiler will ignore anything above:

Code Snippet

#include "stdafx.h"

You need to move your include to <iostream> below this line or put it inside stdafx.h.

John.





Re: Visual C++ Language 'std' : does not exist or is not a namespace

Geo Babu

Hi John,
I tried the solution, but while compiling its giving error,

fatal error C1083: Cannot open include file: 'iostream': No such file or directory
Now I am using the TEXT(" ") function. Is this cout works only in console applications..
My project is Pocket PC application.

thank you,
Geo





Re: Visual C++ Language 'std' : does not exist or is not a namespace

Nishant Sivakumar

Looks like your VC++ directory settings are not correctly configured. Try resetting to defaults or add the right paths to the Include-directory path.





Re: Visual C++ Language 'std' : does not exist or is not a namespace

Geo Babu



Every file in the project other than this file works fine with same directory settings. So is it be a problem.. ..

in a header file , i found a line,

#if !defined(AFX_PROPPAGE1_H__C6F8F7C0_3380_49F1_B17A_72DC381C09AE__INCLUDED_)
#define AFX_PROPPAGE1_H__C6F8F7C0_3380_49F1_B17A_72DC381C09AE__INCLUDED_


what does the number (red colored) indicate. Is this is some kind of key or some thing other than that...

thank you,
Geo




Re: Visual C++ Language 'std' : does not exist or is not a namespace

Nishant Sivakumar

The #defines are to ensure that the header files are only included once in a compilation unit - the newer method is to use #pragma once. Your <iostream> problem is due to something else.

Could you post a minimal code snippet that gives you that error





Re: Visual C++ Language 'std' : does not exist or is not a namespace

_johnr_

Hi Geo,

embedded VC++ 3.0.

Missed this first time. Unfortunately, <iostream> isn't included with this version of the compiler. If you really need this functionality you'll need to get a third party library.

John.





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;
}





Re: Visual C++ Language 'std' : does not exist or is not a namespace

_johnr_

Hi Geo,

I don't see anything in your code, except for the lines commented out, that would require <iostream> to be included. I assure you the compiler is ignoring anything above "stdafx.h" and is therefore not even trying to include <iostream>. If you want to prove this to yourself try entering some random gibberish that would normally cause a compiler error, or define a global variable and then try to access it in one of your functions. In the first case you will see no errors at all, and in the second case the compiler will complain the variable name is unknown.

Hope this helps.

John.





Re: Visual C++ Language 'std' : does not exist or is not a namespace

Geo Babu

hi John,

Thank you. I got the idea about it, now it says no iostream header file.So is it possible to copy some other iostream header file and paste into to include directory of this evc++...
Or is there any another solution..

thank you,
Geo





Re: Visual C++ Language 'std' : does not exist or is not a namespace

Geo Babu

hi,
I copied those file , now its working ...
thank you ,,,

Geo..