Function issue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
    WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile(L"C:\\*",&file);  //it says the L is incompatible
    if (search_handle)
    {
        do
        {
            std::wcout << file.cFileName << std::endl;
        }while(FindNextFile(search_handle,&file));
        CloseHandle(search_handle);

    }

}


I'm not sure what's wrong....stumped.
Last edited on
closed account (Dy7SLyTq)
well, isnt L just for floats and ints?
well, isnt L just for floats and ints?

The prefix 'L', when used with a string literal, is used to signify a type of wchar_t[].

http://msdn.microsoft.com/en-us/library/69ze775t(v=vs.80).aspx

I'm not sure what's wrong....stumped.

You are attempting to pass an argument of type wchar_t[] to a function that requires an argument of type const char*. Removing the 'L' that appears beside the first argument being passed to the FindFirstFile() function will fix this error.

 
HANDLE search_handle=FindFirstFile("C:\\*",&file);
Last edited on
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>
using namespace std;

#include <cwchar> 
using namespace std;


#include <string>
using namespace std;

#include <Windows.h>
using namespace std;

char response;
string a;


int main()
{
	

	cout << "Would you like to play a game? Y/N?";

	cin >> response;
	{
	if (response == 'y');
		cout << "What game would you like to play? Please type in exactly what the game is called including spaces, dashes, or capitalization.";
	cin >> "a";
	
	{
    WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);
    if (search_handle)
    {
        do
        {
            std::wcout << file.cFileName << std::endl;
        }while(FindNextFile(search_handle,&file));
        CloseHandle(search_handle);

    }

}

    

    if (response == 'n')
		cout << "Goodbye!";

	//countdown loop
  for (int n=3; n>0; n--) {
    cout << n << ", ";
  }
  cout << "CIAO!\n";
  return 0;
}


When I try to debug this program it works until I type in the program I want it to search for. Then the console gives a list of computer files and i cant type anything in. Also, a thing pops up saying would you like to break, cancel, or continue. Stumped to the maximization.
Last edited on
When I try to debug this program it works until I type in the program I want it to search for. Then the console gives a list of computer files and i cant type anything in. Also, a thing pops up saying would you like to break, cancel, or continue. Stumped to the maximization.

I don't know why you have placed curl brackets throughout your source code. Are you using them to limit the lifetime of your variables? I've removed them from the source code below.

You are attempting to call std::basic_istream::operator>>() with an erroneous argument. The string literal "a" is an lvalue, and it cannot be assigned a new value. You must provide an rvalue that the member function is able to modify. Perhaps you have mistaken the std::cout object with std::cin object?

http://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt

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
#include <iostream>
#include <cwchar>
#include <string>
#include <Windows.h>
using namespace std;

char response;
string a;

int main()
{
    

    cout << "Would you like to play a game? Y/N?";

    cin >> response;
    if (response == 'y');
        cout << "What game would you like to play? Please type in exactly 
what the game is called including spaces, dashes, or capitalization.";
    cout << "a";

    WIN32_FIND_DATA file;
    HANDLE search_handle=FindFirstFile("C:\\*",&file);
    if (search_handle)
    {
        do
        {
            std::wcout << file.cFileName << std::endl;
        }while(FindNextFile(search_handle,&file));
        CloseHandle(search_handle);

    }

    

    if (response == 'n')
        cout << "Goodbye!";

    //countdown loop
  for (int n=3; n>0; n--) {
    cout << n << ", ";
  }
  cout << "CIAO!\n";
  return 0;
}
Last edited on
There are no red lines under anything, so it seems like there wouldn't be any errors. But the break, continue, or cancel message is still the same. Even if I type in "N" instead of "Y". I think the issue is with the function. Thanks for helping me so far.
Topic archived. No new replies allowed.