C++ char and fstream

I have a C++ Program that is suppost to take a file, and send keys of all the contents in it. here is part of it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <windows.h>
#using <System.dll>
using namespace std;

void Say(char* message, int size)
{
int lc=0;
do{
keybd_event(VkKeyScan(message[lc]),0,KEYEVENTF_EXTENDEDKEY,0);
keybd_event(VkKeyScan(message[lc]),0,KEYEVENTF_KEYUP,0);
lc=lc+1;
}while(lc<size);
keybd_event(VK_RETURN,0,KEYEVENTF_EXTENDEDKEY,0); //Presses Return
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0); //Presses Return
}
void Read(ifstream & in, string &varhere)//fin
{
	in >> varhere;
}
void ohai()
{
	ifstream fin;
	fin.open("U.txt");
	cout << "Choose an option 1 2 or 3 1 only works righ now.." << endl;
	system("cls");
	int option;
	


	cin >> option;
	if (option == 1)
	{
	
	string stuff = "BL";
	for (int i=0;i<=9999999999999999999;i++)
	{
	Read(fin, stuff); 
	Say(stuff,stuff.size);
	}
	}
	else 
	{
		cout << "Error!" << endl;
		exit(1);
	}
	
fin.close();
}
int main()
{
ohai();
}
Line 42 must be Say(stuff.c_str(),stuff.size()); // .c_str() returns onst char* equivalent of std::string
and change void Say(char* message, int size) to void Say(const char* message, int size) // you need const here because .c_str() returns const char*

http://www.cplusplus.com/reference/string/string/c_str/
Last edited on
Topic archived. No new replies allowed.