Function-to-read

Hello, i have a question: theres any funtion with what i can read all files name and display it on screen?

*Sorry for my bad english*
*I am newbie in c++*

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
#include <iostream>
#include <string>
#include <stdlib.h>
#include <sstream>

using namespace std;
string n;
stringstream ss;

int main()
{
cout<<"Detecting all files name"<<endl;

//the detecting funtion

cout<<"C:\Users\cosmi\Desktop\Music\Spag Heddy-Permanent.mp3"<<endl; //This is an example for name
cout<<".....<<"endl;

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

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

//the end

return 0;
} 


soo, theres any funtions to read the name files?
Thanks in advance
I am on Code::Block, something of those is dont working .... (all its not working) *sorry for my english*
Are you running Windows?
Have you included Windows.h?
Yes, i have windows, i include Windows.h and it gived me 3 errors, this is not an homework if you want to know
What are the errors?
1
2
3
4
5
6
7
||=== Build: Debug in Detect Name Files (compiler: GNU GCC Compiler) ===|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|5|error: '::main' must return 'int'|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp||In function 'int main(int, TCHAR**)':|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|13|error: return-statement with no value, in function returning 'int' [-fpermissive]|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|20|warning: format '%d' expects argument of type 'int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]|
F:\Projects\C++\Code Blocks\Mine\Detect Name Files\main.cpp|21|error: return-statement with no value, in function returning 'int' [-fpermissive]|
||=== Build failed: 3 error(s), 1 warning(s) (0 minute(s), 8 second(s)) ===|


While trying to do https://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx
Last edited on
Try this 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
#if defined (_UNICODE) || defined (UNICODE)
#error "Unicode not supported - use Multi-Byte Character Set" 
#endif

#include <windows.h>
#include <stdio.h>

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

  const char szInitialDir[] = "C:\\Temp\\*.*";

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


Adjust const char szInitialDir[] = "C:\\Temp\\*.*"; to your needs
||=== 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|19|warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'DWORD {aka long unsigned int}' [-Wformat=]|
||Error: %u ", GetLastError ());|
||=== Build finished: 1 error(s), 1 warning(s) (0 minute(s), 1 second(s)) ===|

I hope i will fix it :/
Try this:
 
 printf ("Error: %lu ", GetLastError ());

Looks like this GNU GCC Compiler is meaner than a Pascal compiler.

According to MSDN a DWORD is an unsigned int.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx
Thanks you a lot! I solve the problem :D
Topic archived. No new replies allowed.