Menu

Help with wcin/ wcout?

2008-07-01
2012-09-26
  • Walter Horvath

    Walter Horvath - 2008-07-01

    I'm sorry if this was already covered in another post, but for some reason, Dev-C++ doesn't seem to recognise the <iostream> file, or it atleast does so conditionally. In the code below:

    ============================

    include <iostream>

    include <string>

    include <wchar.h>

    include <cstdlib>

    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {
    std::wstring iobuf;
    cout << "Enter a number\n";
    getline(wcin,iobuf);
    wcout << iobuf << "\n";
    int n = _wtol(iobuf.c_str());
    cout << "n = " << n << "\n";
    return 0;
    }

    ============================

    It returns the following errors:

    7 C:\Dev-Cpp\main.cpp _TCHAR' has not been declared 8 C:\Dev-Cpp\main.cpp ISO C++ forbids declaration ofargv' with no type
    C:\Dev-Cpp\main.cpp In function int _tmain(int, int**)': 11 C:\Dev-Cpp\main.cppwcin' undeclared (first use this function)
    12 C:\Dev-Cpp\main.cpp `wcout' undeclared (first use this function)

    Do you have to declare wcin/ wcout seperately from <iostream>?

    Sorry if this question is simple, redundant or repeated. I'm learning on my own in my spare time and I'm fairly new. Thanks.

     
    • Walter Horvath

      Walter Horvath - 2008-07-01

      Furthermore, the code below from Microsoft Developer's Network won't even execute correctly:

      =========================

      // iostream_cerr.cpp
      // compile with: /EHsc
      // By default, cerr and clog are the same as cout

      include <iostream>

      include <fstream>

      using namespace std;

      void TestWide( )
      {
      int i = 0;
      wcout << L"Enter a number: ";
      wcin >> i;
      wcerr << L"test for wcerr" << endl;
      wclog << L"test for wclog" << endl;
      }

      int main( )
      {
      int i = 0;
      cout << "Enter a number: ";
      cin >> i;
      cerr << "test for cerr" << endl;
      clog << "test for clog" << endl;
      TestWide( );
      }

      =========================

       
    • cpns

      cpns - 2008-07-01

      First always post the "Compile Log" tab text, not the filtered "Compiler" tab text. It contains more complete information, including all your build options.

      > 7 C:\Dev-Cpp\main.cpp `_TCHAR' has not been declared

      _TCHAR is not defined in any of the headers you included. It is defined in tchar.h http://msdn.microsoft.com/en-us/library/c426s321(VS.80).aspx

      > 11 C:\Dev-Cpp\main.cpp wcin' undeclared (first use this function) &gt; 12 C:\Dev-Cpp\main.cppwcout' undeclared (first use this function)

      Take a look in the actual header file, I believe you will find that they are defined only when some particular wide-character support macro is defined.

      > Furthermore, the code below from Microsoft Developer's
      > Network won't even execute correctly:

      Give us a clue! Don't make us read your mind - it will render you senseless. ;-) What does it do, and what do you expect it to do? Posting a link to the original source would be useful too! (never mind: http://msdn.microsoft.com/en-us/library/6xwbdak2.aspx ). Since you have already observed that wcin and wcout are not defined, I am struggling to understand how you could have executed it at all, as it would not have compiled.

      Clifford

       
    • Stanis Kiadidi

      Stanis Kiadidi - 2008-07-13

      Hi,Walter.
      I'm new to C++ too and I've just started using Dev-C++ 4.9.9.2 Beta(You can download it at this address: http://internap.dl.sourceforge.net/sourceforge/dev-cpp/devcpp-4.9.9.2_setup.exe).
      I don't know if you've already gotten the solution to your problem. I used this peace of code to test this beta version and it worked:

      include <iostream.h>

      int main()
      {
      cout<<"The Compiler Works";
      return 0;
      }

      Instead of <iostream> use <iostream.h> (http://www.cprogramming.com/compiler.html)

      I hope this will help. Don't forget that I used Dev-C++ 4.9.9.2 Beta.

       
      • cpns

        cpns - 2008-07-14

        Yo seem to be answering a different question in any case. What has this dot to do with wide character I/O?

         
        • Wayne Keen

          Wayne Keen - 2008-07-14

          Probably assumed the "w" in front was a typo.

          ;)

          Wayne

           
      • Wayne Keen

        Wayne Keen - 2008-07-13

        "Instead of <iostream> use <iostream.h> (http://www.cprogramming.com/compiler.html)"

        NO! Don't ooffer advice if you are going to be THIS WRONG!

        iostream.h has been deprecated (i.e. old and wrong) for 10 years.

        Wayne

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.