Object Oriented

Pages: 12
For Windows, it's not the operating system or cmd that does this. It's the runtime that happens before main starts that determines if wildcards are expanded. You can disable or enable this in MinGW ("globbing"), but I don't know how to do it in Visual Studio.

Edit: Apparently with Visual Studio, to support globbing, you need link with setargv.obj
https://docs.microsoft.com/en-us/cpp/c-language/expanding-wildcard-arguments?redirectedfrom=MSDN&view=msvc-160

For MinGW, to disable it, you need to something like:
1
2
3
#if defined(__MINGW64__) || defined(__MINGW32__)
int _dowildcard = -1; 
#endif 

(not tested, been a while since I've messed with this)
Last edited on
Cheers, Ganado!
cl test.cpp /link setargv.obj
made it work.

No idea what you do in Visual Studio, since I don't use that as an IDE.
How to add setargv.obj within the VS 2019 IDE:

1. bring up your project's property pages.

2. under Linker->Input->Additional Dependencies select <Edit...> from the drop-down menu.

3. In the dialog box's top edit box add setargv.obj. Select Ok.

You should now see the additional dependencies has changed to include setargv.obj.

4. Select Ok to close out the dialog. OR Apply to edit other items.

5. RE-build and now the VS 2019 C++ app should expand wildcard arguments.

I found how to do this here:
https://stackoverflow.com/questions/23882112/how-to-add-static-libraries-to-a-visual-studio-project

Since setargv.obj is already a part of VS C/C++ libraries I didn't need to add additional include or library directories.

FYI, whenever I set a project's properties via the IDE property pages I try to make any changes with the Configuration option set to "All Configurations" and the Platform option set to "All Platforms." So I don't have to set the options individually for Debug/Release or x86/x64.
Thanks, @Furry Guy and @Ganado. Useful for completeness.

Command-line wildcard expansion is a useful feature. Sadly, being an almost full-time user of g++ and gfortran I thought it was universal (and I actually found it by accident there).
Nice! :) :)
Yes, command-line argument expansion is useful, even if I don't need it for a particular project. I can't visualize an instance where I deem it something to manually disable with a non-MS compiler.

I am somewhat tempted to add the file to be part of the VS defaults when creating a new project.

How to do that can be found here:
http://www.cplusplus.com/forum/lounge/271176/

lastchance wrote:
I thought it was universal

It is universal, except with MSVC. :Þ
Oh, thank you, Ganado, for giving me a push to start scraping the bowel's of the internet to find how to add the file to VS' IDE. You pointed me in the general vicinity of where to look with your link. :)
Glad to help.

While I was writing this many more answers have appeared.
It is a try at the first question with multiple files in a folder.
I write the given string to multiple files and retrieve the strings between <BODY> and </BODY>
They are all the same, I save the same string in each file, but it should be general.
Create a temp folder and run this code in 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <string>
#include<iostream>
#include <fstream>
#include <sstream>
std::string mid(std::string str, int pos1, int length)
{
    int i;
    pos1-=1;
   std:: string temp = "";
   if (pos1<0){return str;};
    for(i = pos1; i < pos1+length; i++)
    {
    	if (i>str.length()-1) {return temp;};
        temp += str[i];
    }
    return temp;
}

int instr(int n,std::string istring_,std:: string tofind){
	std::string istring=mid(istring_,n,istring_.length());
    if (istring.find(tofind)!=istring.npos){
        return istring.find(tofind)+1;
    }else{
        return 0;
    }
}

std::ifstream::pos_type filesize(const char* filename)
{
    std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
    return in.tellg(); 
}

template <typename L>
 void load(const char * filename,L  &array)
{
	int s=filesize(filename)/sizeof(array[0]);
	array.resize(s);
	FILE * f = fopen(filename, "rb");
	auto ap = &array[0];
	fread(ap,array.size()*sizeof(array[0]),1,f); 
   fclose(f);
}

int main()
{
     
 int p1=0,p2=0;
 std::string s,g;
 std::string filename;
 for(int i=1;i<4;i++) // create test files
 {  
 if (i==1) filename= "test.xml";
 if (i==2) filename= "test1.xml"; 
 if (i==3) filename= "test2.xml";     
std::ofstream( filename ) <<
R"(<REUTERS ... >
<DATE>26-FEB-1987 15:01:01.79</DATE>
<TOPICS><D>cocoa</D></TOPICS>
<PLACES><D>el-salvador</D><D>usa</D><D>uruguay</D></PLACES>
<PEOPLE></PEOPLE>
<ORGS></ORGS>
<EXCHANGES></EXCHANGES>
<COMPANIES></COMPANIES>
<UNKNOWN> ... </UNKNOWN>
<TEXT> ...
<TITLE>BAHIA COCOA REVIEW</TITLE>
<DATELINE> SALVADOR, Feb 26 - </DATELINE>
<BODY>Showers continued throughout
the week in the Bahia cocoa zone, alleviating the drought since
...
...
Brazilian Cocoa Trade Commission after
carnival which ends midday on February 27.
Reuter
&#3;</BODY></TEXT>
</REUTERS>
)" ;
}

system("dir /b > files.txt");
load("files.txt",g);
std::istringstream dir(g);
std::string t;
	while ( dir>>t)
	 {
	 load( t.c_str(),s);
std::cout<<"file:"<<t.c_str()<<std::endl;
p1=instr(1,s,"<BODY>")+6;// 6=length of <BODY>
p2=instr(1,s,"</BODY>");
std::string ans=mid(s,p1,p2-p1);
std::cout<<ans<<std::endl<<std::endl;
     }

system("pause");
}
 
 

Then you can delete the temp folder.
g++ Win 10


Topic archived. No new replies allowed.
Pages: 12