Maximus Posted March 18, 2012 Report Posted March 18, 2012 am codul urmator :#include "stdafx.h"#include <iostream>#include <fstream>#include <string>#include <windows.h>using namespace std;int main () { string line; ifstream myfile ("1.txt"); getline (myfile,line); HGLOBAL hText; char *pText; hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100); pText = (char*)GlobalLock(hText); strcpy(pText, line); GlobalUnlock(hText); OpenClipboard(NULL); EmptyClipboard(); SetClipboardData(CF_TEXT, hText); CloseClipboard(); myfile.close(); return 0;}cand dau debug imi zice :Error 1 error C2664: 'strcpy' : cannot convert parameter 2 from 'std::string' to 'const char *' c:\users\max\documents\visual studio 2010\projects\test\test\test.cpp 21 1 test 2 IntelliSense: no suitable conversion function from "std::string" to "const char *" exists c:\users\max\documents\visual studio 2010\projects\test\test\test.cpp 21 16 testin fisierul 1.txt este doar 1 linie scrisa, si vreau sa pun linia in clipboard.ma poate ajuta cineva ? Multumesc.P.S. Daca se poate rezolvare+explicare ar fi si mai bine pt mine.Nu sunt avansat. Quote
totti93 Posted March 18, 2012 Report Posted March 18, 2012 (edited) #include "stdafx.h"#include <iostream>#include <fstream>#include <string>#include <windows.h>using namespace std;int main () { string line; ifstream myfile ("1.txt"); getline (myfile,line); HGLOBAL hText; char *pText; hText = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 100); pText = (char*)GlobalLock(hText); char *linec; linec = &line[0]; strcpy(pText, linec); GlobalUnlock(hText); OpenClipboard(NULL); EmptyClipboard(); SetClipboardData(CF_TEXT, hText); CloseClipboard(); myfile.close(); return 0;}strcpy (char *, char *), si tu ai pus string. Am creat un pointer de tip char pe care l-am setat pe adresa primul caracter. Edited March 18, 2012 by totti93 1 Quote
Maximus Posted March 18, 2012 Author Report Posted March 18, 2012 @totti93 ; multumesc. merge perfect.thx again. respect +1 Quote