CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] what's wrong with 'cout' with strings?:(

    see these class:
    Code:
    #include <iostream>
    #include <Windows.h>
    #define MY_BUFSIZE 1024
    using namespace std;
    
    
    
    
    class Console
    {
    char pszOldWindowTitle[MY_BUFSIZE];
    
    
    	public:
    string Title() //the problem seems to be here, but no erro message here
    	{		
    		GetWindowText(GetForegroundWindow(), pszOldWindowTitle, GetWindowTextLength(GetForegroundWindow()) + 1);
    		return string(pszOldWindowTitle);
    	}
    	
    	void Title(string title)  //these procedure works fine
    	{		
    		SetConsoleTitle(title.c_str());
    	}
    };
    (sorry the indention, but i can't use 'TAB' key)
    and heres how i use it:

    Code:
    #include "stdafx.h"
    #include "Console.h"
    #include <iostream>
    #include <conio.h>
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Console a;
        string b =string(a.Title());
    
    
        cout << "Title: " << b << endl; //i get 1 problem in second '<<'
    
    
        Sleep(5000);
    
    
        a.Title("Hello World");
    
    
        getch();
    
    
        return 0;
    }



    error message:

    1 - "error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)";

    2 - " IntelliSense: no operator "<<" matches these operands".

    what is wrong with cout???? isn't the 1st time that i get these type of error, but i continue without understand why
    can anyone explain to me?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: what's wrong with 'cout' with strings?:(

    Did you try to
    Code:
    #include <string>
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by VictorN View Post
    Did you try to
    Code:
    #include <string>
    thank you. so every that i use the string, i must include that file.. thank you very much.
    i have more 2 questions for close the topic:

    1 - what means: title.c_str()?
    (title it's a string variable)

    2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
    why these warning? the '_getch' can be used in Dev C++ too?

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by Cambalinho View Post
    thank you. so every that i use the string, i must include that file.. thank you very much.
    i have more 2 questions for close the topic:

    1 - what means: title.c_str()?
    (title it's a string variable)

    2 - "warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch."
    why these warning? the '_getch' can be used in Dev C++ too?
    1) See http://www.cplusplus.com/reference/string/string/c_str/

    2) See http://stackoverflow.com/questions/8...-is-deprecated
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: what's wrong with 'cout' with strings?:(

    thanks for all
    VictorN and 2kaud: do you recive the Rate?
    (if not... sorry, it's a forum problem\rules)

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by Cambalinho View Post
    thanks for all
    VictorN and 2kaud: do you recive the Rate?
    (if not... sorry, it's a forum problem\rules)
    Unfortunately no, I haven't received your Rate.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: what's wrong with 'cout' with strings?:(

    Quote Originally Posted by 2kaud View Post
    Unfortunately no, I haven't received your Rate.
    i'm realy sorry about that... it's by forum rules

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured