wcout and wcin not working...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

wcout and wcin not working...

Post by arras »

For some reason code below doesn't compile and DevC++ give me 'wcout' undeclared (first use this function) error:

Code: Select all

#include <iostream>
using namespace std;

int main() 
{
   wcout << L"Hallo Everybody";  
}
wcout and wcin should be declared in iostream, does anybody know what is wrong?
gmpiglet
Posts: 6
Joined: Mon Dec 20, 2004 1:20 pm

Post by gmpiglet »

I thought it was just cout, rather than wcout. What are you trying to do?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

w stays for wide character standard iostream function cout deal just with simple characters and you can't sent wchar_t string in to the stream. For that there is separate set of functions, mostly with w in front of name. Look here:http://msdn.microsoft.com/library/defau ... embers.asp
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

my guess ( i've never used and really know nothing about DevCPP ) is that they just aren't implemented in DevCPP yet.

Try using wprintf and wscanf, C style input/output functions?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Yes, that is what I was thinking too since to me there seems no other reason. On the other hand I am not expert programer, so I may use help of more experienced ones.

I was looking in to iostream file and there stays:

Code: Select all

#ifndef _CPP_IOSTREAM
#define _CPP_IOSTREAM	1

#pragma GCC system_header

#include <bits/c++config.h>
#include <ostream>
#include <istream>

namespace std 
{
  /**
   *  @name Standard Stream Objects
   *
   *  The <iostream> header declares the eight <em>standard stream
   *  objects</em>.  For other declarations, see
   *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#10 and the
   *  @link s27_2_iosfwd I/O forward declarations @endlink
   *
   *  They are required by default to cooperate with the global C library's
   *  @c FILE streams, and to be available during program startup and
   *  termination.  For more information, see the HOWTO linked to above.
  */
  //@{
  extern istream cin;		///< Linked to standard input
  extern ostream cout;		///< Linked to standard output
  extern ostream cerr;		///< Linked to standard error (unbuffered)
  extern ostream clog;		///< Linked to standard error (buffered)

#ifdef _GLIBCPP_USE_WCHAR_T
  extern wistream wcin;		///< Linked to standard input
  extern wostream wcout;	///< Linked to standard output
  extern wostream wcerr;	///< Linked to standard error (unbuffered)
  extern wostream wclog;	///< Linked to standard error (buffered)
#endif
  //@}

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;
} // namespace std

#endif
This file is in include/c++/3.3.1 directory of DevC++

wprintf and wscanf works without problems on the other hand.
Guest

Post by Guest »

See that #ifdef _GLIBCPP_USE_WCHAR_T ?

the block that defines wcin and wcout is only active when there is a
preprocessor constant defined named _GLIBCPP_USE_WCHAR_T

That is simple to do:
place a line:
#define _GLIBCPP_USE_WCHAR_T

above your #include <iostream.h> line.
Usually you can also do stuff like that on the command line, but I don't know devc++ so can't help you with that method.
Anyway, that should take care of the compile-phase.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Hmm ...did like you sugested, which seems to be logical but got lot of compile errors in lot of other files like iosfwd, ios, ostream, iostream ..ect.

Does code ot the begining of this post work on other compilers? Can somebody try it? ...thanks.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Code: Select all

wchar_t test[255];
swprintf ( test, 255, L"Wide Test\n" );
wcout << test << endl;

That code works perfectly using Visual Studio 2003.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

in DevC++ this code give me 2 errors:
invalid conversion from 'int' to 'const wchar_t*' in second line
'wcout' undeclared as before...
Post Reply