Please tell me what is wrong? The program does not compile and sin on
"" source.GetLeight () + 1) "" and "LPCSTR (source)", how to fix it? Thank you very much!

#include "stdafx.h" #include <iostream> #include <string> #include <windows.h> #include <string.h> #pragma comment(lib, "user32.lib") #pragma comment(lib, "Framedyn.lib") using namespace std; string First("* ["), second("|"), three, fifi("]"), link, source; int main(void) { setlocale(LC_ALL,"Russian"); //Π² эту ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ Π½ΡƒΠΆΠ½ΠΎ Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ тСкст, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π² дальнСйшСм помСстится Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° //Ρ‡Ρ‚Π΅Π½ΠΈΠ΅ тСкста ΠΈΠ· Π±ΡƒΡ„Π΅Ρ€Π° ΠΎΠ±ΠΌΠ΅Π½Π° cout<< "Π’Π²Π΅Π΄ΠΈ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΌΠΎΠ΄Π°:"; cin>> three; string fromClipboard;//Π² эту ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ сохраним тСкст ΠΈΠ· Π±ΡƒΡ„Π΅Ρ€Π° ΠΎΠ±ΠΌΠ΅Π½Π° if ( OpenClipboard(0) )//ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° { HANDLE hData = GetClipboardData(CF_TEXT);//ΠΈΠ·Π²Π»Π΅ΠΊΠ°Π΅ΠΌ тСкст ΠΈΠ· Π±ΡƒΡ„Π΅Ρ€Π° ΠΎΠ±ΠΌΠ΅Π½Π° char*chBuffer=(char*)GlobalLock(hData);//Π±Π»ΠΎΠΊΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ fromClipboard=chBuffer; GlobalUnlock(hData);//Ρ€Π°Π·Π±Π»ΠΎΠΊΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ CloseClipboard();//Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° } cout<< First<<fromClipboard<< second<< three<< fifi<< endl; link=First+fromClipboard+second+three+fifi; cout<< link<< endl; source=link; //запись тСкста Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° if(OpenClipboard(0))//ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° { HGLOBAL hgBuffer; char* chBuffer; EmptyClipboard(); //ΠΎΡ‡ΠΈΡ‰Π°Π΅ΠΌ Π±ΡƒΡ„Π΅Ρ€ hgBuffer=GlobalAlloc(GMEM_DDESHARE, source.GetLeight()+1);//выдСляСм ΠΏΠ°ΠΌΡΡ‚ΡŒ chBuffer=(char*)GlobalLock(hgBuffer); //Π±Π»ΠΎΠΊΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ strcpy(chBuffer, LPCSTR(source)); GlobalUnlock(hgBuffer);//Ρ€Π°Π·Π±Π»ΠΎΠΊΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ°ΠΌΡΡ‚ΡŒ SetClipboardData(CF_TEXT, hgBuffer);//ΠΏΠΎΠΌΠ΅Ρ‰Π°Π΅ΠΌ тСкст Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° CloseClipboard(); //Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° } return 0; } 
  • How sin? That writes? - uzumaxy
  • 2
    In std::string there is no GetLeight method, not even GetLength , so the compiler correctly curses. - VladD
  • So how to do it, I realized, but how to arrange? - Alego22
  • Checkout what? Here is a list of std::string methods: en.cppreference.com/w/cpp/string/basic_string - VladD
  • one
    Then read the basics urgently. Find a book on C ++ (namely a book, video tutorials are not rolling) and study it. For books, look for questions on this site, discussed an infinite number of times. When you understand how std::string differs from char* , you can start writing programs. - VladD

1 answer 1

For MS-specific types, it is convenient to use the MSDN site or the local MSVS help. For example, on this page you can find that the type CString is contained in the header file "afx.h". http://msdn.microsoft.com/en-us/library/aa300688%28v=vs.60%29.aspx

To use the MFC tools (availability of the same header files), you need to make sure that by the menu of the Studio Project->имя_ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π° properties...->Configuration Properties->General->Project Defaults property " Use of MFC " is set to " Use MFS in a ... "

LPCSTR is not a class, but a synonym of type const char* (if you hover the mouse over this type, you can see a popup with the text typedef substitutions), read as L ong P ointer C onst S tring, that is, a long pointer to a constant string (in From the string - char arrays with an additional element - the null character '\ 0'). Therefore it is impossible to call the constructor like this. A string is created as always:

 LPCSTR str = "Sample text"; 

In this context, the C-style c_str() has the c_str() method for accessing the pointer to a string in the std :: string class, and the c_str() method for the CString.

 // для std::string source strcpy(chBuffer, source.c_str()); // для CString source strcpy(chBuffer, source.GetBuffer()); // для LPCSTR source strcpy(chBuffer, source);