Click to See Complete Forum and Search --> : Simple problem... for you


Sebz
April 21st, 2004, 03:42 AM
I'm just a beginner in C++.NET. Can you tell me what's wrong here?

#include "stdafx.h"

#include <fstream>



int _tmain(int argc, _TCHAR* argv[])
{
cout << "Dzialaj";
return 0;
}

Builder says:
error C2065: 'cout' : undeclared identifier

I don't understand... the "iostream" library is added to stdafx... but even if I add this to this file it doesn't works...

Zaccheus
April 21st, 2004, 07:57 AM
Try:

std::cout << "Dzialaj";

or even:

std::cout << "Dzialaj" << std::endl;

Andreas Masur
April 21st, 2004, 08:32 AM
As mentioned, you need to map the namespace 'std' to your application.

The following shows you the four different methods to map a namespace...

// Using the full member name, including the namespace it belongs to:
std::cout << "Hello World";


// By taking advantage of Using-Declarations:
using std::cout; // This declares cout in the current
// scope as synonym for std::cout
cout << "Hello World";


// By taking advantage of Using-Directives:
using namespace std; // Which specifies that the current
// scope can refer to names in the
// 'std' namespace without using
// full qualifiers. This is mostly
// used when porting legacy code.
cout << "Hello World";


// Using aliases:
namespace X
{
namespace Y
{
class Z { ... };
}
}

X::Y::Z // The full qualifier for 'Z' is
// 'X::Y::Z'

namespace w = X::Y; // This declares 'w' as an alias for
// namespace 'X::Y'

w::Z // Access 'Z' using 'w::Z'

Sebz
April 22nd, 2004, 01:28 AM
Thank you. Now I understand...
I'll try to ask you more difficult question in the future... :)

malg
April 23rd, 2004, 01:36 PM
Hi,

cout is incuded in std namespace in c++.nte so if you inlude :

using namspace std;

just after "#include" will sort out your cout error

you do not need to do anything else;

this should sort out many of your problems with future applications


Malg

Sebz
April 24th, 2004, 11:19 AM
Thank you...

Can you tell me how to declare a "string" and operate on it?
I remember AnsiString from Borland and remember also how easy it was to operate on it...
Is there any similar type in VC++ on which I could opetate as easy as it was in Borland C++ Builder...?
How can I use it? What libraries should I link in source files?
I tried to do that in many ways but it didn't work.
I suppose the problem is in some markups or inheritance (inherity) from upper libraries (what libraries?)...

Sorry for those simple questions but the Microsoft's help is not so easy to use as Borland's one... I'm trying to find any book about VC++.NET but there are no good publications in Polish...
:)

I need a book which will have informations about a forms and mathods related with forms, markups and others subjects related with creating aplications in VC++...

Greetings and once again THANK YOU ALL!

DeepButi
April 26th, 2004, 03:39 AM
#include atlstr.h> // there should be a "<" before atlstr but if I post it the line doesn't show up

...

CString mystring; // and now a little bit of codeguru, google ... search ...


Hope it helps

Sebz
April 26th, 2004, 06:43 AM
It works.... thanks.... :thumb: