2012-11-11 3 views
1

.txt 파일의 텍스트에 한정자를 입력 한 후 입력하는 데 문제가 있습니다. .txt 파일에 "type :"이라는 단어가 있으면 그 다음에 아무 것도 char에 넣을 수 있습니다. 지금까지 내 코드 : 애프터 그래서텍스트 파일에서 입력하여 문자를 가져옵니다. C++

#include "stdafx.h" 
#include <windows.h> 
#include "VKH.h" 
#include "Strmif.h" 
#include <iostream> 
#include <stdio.h> 
#include <string> 
#include <fstream> 

void GetDocumentandRead() { 
string line; 
ifstream myfile (line1); 
if (myfile.is_open()) 
{ 
    while (!myfile.eof()) 
    { 
    getline (myfile,line); 
    char aline[100]; 
    strcpy(aline, line.c_str()); 
    printf(aline, "\n"); 
    if (line.compare("mouseup") == 0){ 
     MouseUp(10); 
    } 
    if (line.compare("mousedown") == 0){ 
     MouseDown(10); 
    } 
    if (line.compare("mouseright") == 0){ 
     MouseRight(10); 
    } 
    if (line.compare("mouseleft") == 0){ 
     MouseLeft(10); 
    } 
    if (line.compare("mouseclick") == 0){ 
     MouseClick(); 
    } 
    if (line.compare("enter") == 0){ 
     Enter(); 
    } 
    if (line.compare("ctrltab") == 0){ 
     CtrlTab(); 
    } 
    if (line.compare("tab") == 0){ 
     Tab(); 
    } 
    if (line.compare("altf4") == 0){ 
     AltF4(0); 
    } 
    if (line.compare("alttab") == 0){ 
     AltTab(); 
    } 
    if (line.compare("mousecenter") == 0){ 
     MouseCenter(); 
    } 
    if (line.compare(6,5,"type:") == 0){ 
     //Don't know what to put here... 
    } 
    } 
    myfile.close(); 
} 

else printf("\nUnable to open file\n\n"); 

} 

"유형 :"텍스트에 그것을 입력합니다 파일이 내가 TypeStr 불렀다() 함수를 사용;을

void TypeStr(char *lpszString) 
{ 
    char cChar; 
    while((cChar=*lpszString++)) // loops through chars 
    { 
    short vk=VkKeyScan(cChar); // keycode of char 
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,0,0);} // hold shift if necessary 
    keybd_event((unsigned char)vk,0,0,0); // key in 
    keybd_event((unsigned char)vk,0,KEYEVENTF_KEYUP,0); // key out 
    if((vk>>8)&1){keybd_event(VK_LSHIFT,0,KEYEVENTF_KEYUP,0);} // release shift if necessary 
    } 
} 

어떤 도움을 주시면 감사하겠습니다. 감사!

+1

무엇이 질문입니까? – alestanis

+0

이 코드와 함께 입력 할 수있는 기존 "텍스트"파일의 ** 작은 ** 샘플을 게시하는 것 외에 원하는 것을 명시했습니다. 이것이 당신이 시도한 것의 전부입니까? 아마도 그것을 디버깅? 테스트 및 디버깅에서 무엇을하고있는 것처럼 보입니까? – WhozCraig

답변

3

먼저 TypeStr 함수를 다시 작성하여 const char *이되도록해야합니다. 이처럼

void TypeStr(const char *lpszString) 
{ 
    ... 
} 

다른 변경이 필요하지 않습니다.

그럼 당신은 당신이 (이것은 일반적으로 좋은 스타일 인에서 떨어져) const char*TypeStr 기능을 변경해야이

if (line.compare(6,5,"type:") == 0){ 
    TypeStr(line.c_str() + 11); 
} 

이유 같은 코드에서 해당 함수를 호출해야합니다입니다 std::stringc_str() 방법 char*이 아닌 const char*을 반환합니다.

+0

왜 "형식 :"뒤에 +11일까요? – acraig5075

+0

@ acraig5075 행의 여섯 번째 문자에서 비교가 시작되므로 "type :"이 다음 5 자이므로 "type :"다음의 첫 번째 문자는 줄의 11 번째 문자입니다 (물론 모두 0이됩니다). – john

+0

감사합니다. – acraig5075

관련 문제