array must be initialized with a brace-enclosed initializer

Hi forum, i dont know how to fix some errors. I try more different ways to fix it but same error's at line 33. Thanks in advance!
*Sorry for my english*
*This is not an homework!*
*Im new in c++"

Code:
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
57
58
59
60
61
#if defined (_UNICODE) || defined (UNICODE)
#error "Unicode not supported - use Multi-Byte Character Set"
#endif

#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sstream>

using namespace std;
string n;
string f1;
string flf;
string f2;
stringstream ss;
string rr;

int main (void)
{
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;

    flf = "*.*";

    cout<<"Enter file's location: "<<endl;
    cin >> f1;

    rr =f1 + flf;

    const char szInitialDir[] = rr;

    printf ("Initial directory: %s", szInitialDir);
    hFind = FindFirstFileA (szInitialDir, &FindFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        printf ("Error: %lu ", GetLastError ());
        system ("pause");
        return EXIT_FAILURE;
    }
    do
    {
        printf ("\nFile: %s", FindFileData.cFileName);

    } while (FindNextFileA (hFind, &FindFileData));

    FindClose (hFind);
    system ("pause");

    cout<<"Which you want to run?"<<endl;
    cin >> n;

    ss << "start " << f1 << n;
    system (ss.str().c_str());

    return 0;

    return EXIT_SUCCESS;
}


Errors:
1
2
3
4
5
6
||=== Build: Debug in Detect Name Files (compiler: GNU GCC Compiler) ===|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp||In function 'int main()':|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|32|error: initializer fails to determine size of 'szInitialDir'|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|32|error: array must be initialized with a brace-enclosed initializer|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|


I still dunno now how to fix those error's, please help me! Thanks in advance!
Last edited on
Is there any reason you use const char [] ? I believe the error is caused by this. Try using a string.
If i not use const char[] there will be more error's, i try also with string and it wont work, more error's, i hope i will fix this problem :/
Last edited on
Try doing this:
 
const char szInitialDir[rr.size()] = rr;
jgg2002 wrote:
Try doing this:
No.

Remove line 32 and rename rr -> InitialDir

Wherever you have szInitialDir now replace it with InitialDir.c_str() (See line 55).
It worked, thanks a lot man! (if i can, i will something like +rep you)
Topic archived. No new replies allowed.