|
i want to call any class from native c++ into (managed-unmanaged) c#. i am looking for other ways except GUID.
|
|
|
|
|
|
I want to write shell programming in UNIX, alao i am new to unix. i have written very simple program for console
ISSUE:
I added some item in map as string int pair, now i am searching string read from commandline and i am unable to find it, but if i use same code with windows . i am able to do same.
Code is as follows
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
map <string, int> m1;
int main(int argc, char* argv[])
{
m1.insert(map <string, int> :: const_iterator::value_type("cd",0));
m1.insert(map <string, int> :: const_iterator::value_type("dir",0));
m1.insert(map <string, int> :: const_iterator::value_type("pwd",0));
m1.insert(map <string, int> :: const_iterator::value_type("echo",0));
m1.insert(map <string, int> :: const_iterator::value_type("help",0));
m1.insert(map <string, int> :: const_iterator::value_type("quit",0));
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
typedef pair <string, int> Int_Pair;
if(argc == 1)
{
cout<<"Please enter unix command..";
}
else
{
string command;
command = argv[1];
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
m1_AcIter = m1.find(command);
if(m1_AcIter == m1.end())
{
cout<<"Didn't find unix command - "<< command<<endl ;
}
else
{
system(command.c_str());
}
}
map <string, int> :: iterator it;
for ( it=m1.begin() ; it != m1.end(); it++ )
cout << (*it).first << " => " << (*it).second << endl;
return 0;
}
now i am running this code
./a.out ls
and i received following output
Didn't find unix command - ls<br />
cd =>; 0<br />
dir =>; 0<br />
echo =>; 0<br />
help =>; 0<br />
pwd =>; 0<br />
quit =>; 0
but same code is working perfectly with windows.
|
|
|
|
|
I don't see a problem here. Your map table does not contain an entry for 'ls' so the program correctly reports it as not being found. Quite how this works on Windows remains a mystery - can you show the working sample?
|
|
|
|
|
Above code is working, But this code is not working
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
map <string, int> m1;
string tokenizeReturnFirst(const string& str,const char& delimiters)
{
string token;
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
string::size_type pos = str.find_first_of(delimiters, lastPos);
if( pos!=string::npos)
{
token = str.substr(lastPos, pos - lastPos);
}
else
{
token = str;
}
return token;
}
int main()
{
m1.insert(map <string, int> :: const_iterator::value_type("cd",0));
m1.insert(map <string, int> :: const_iterator::value_type("dir",0));
m1.insert(map <string, int> :: const_iterator::value_type("pwd",0));
m1.insert(map <string, int> :: const_iterator::value_type("echo",0));
m1.insert(map <string, int> :: const_iterator::value_type("help",0));
m1.insert(map <string, int> :: const_iterator::value_type("quit",0));
map <string, int> :: const_iterator m1_AcIter, m1_RcIter;
typedef pair <string, int> Int_Pair;
ifstream ifile( "test.bat");
if ( ifile.fail() )
{
fprintf(stderr, "Cannot open %s\n", "output_file");
return 0;
}
while (!ifile.eof())
{
string data_string ;
getline(ifile,data_string);
string command = tokenizeReturnFirst(data_string,string::value_type(' '));
cout<<"Searched string - "<<command <<endl;
m1_AcIter = m1.find(command);
if(!command.empty())
{
if(m1_AcIter == m1.end())
{
cout<<"Didn't find unix command - "<< data_string<<endl ;
}
else
{
cout<<"SYSTEM - "<< data_string.c_str()<<endl;
system(data_string.c_str());
}
}
}
return 0;
}
Input file test.bat file content
<br />
ls<br />
pwd<br />
echo<br />
aaa<br />
quit
now i tried to execute
Input
./a.out test.bat
Output:
<br />
Searched string - ls<br />
Didn't find unix command - ls<br />
Searched string - pwd<br />
Didn't find unix command - pwd<br />
Searched string - echo<br />
Didn't find unix command - echo<br />
Searched string - aaa<br />
Didn't find unix command - aaa<br />
Searched string - quit<br />
Didn't find unix command - quit<br />
Searched string -
but file contain this command but output is wrong.
|
|
|
|
|
Don't know what you're testing it on, but your code certainly works on Mac OS X 10.5.8.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
What line terminations does the file have? \n or \r\n? It makes a difference - if you've produced the files in Windows, then they're likely to have \r\n. Unix systems will read the \r as part of the command string, so the command you're looking for will be (for example) 'pwd\r'.
I've just tested that theory on my Mac (saved test.bat with Windows line-endings) and it reflects what you've seen.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
This code works fine on Windows. I cannot see what you are doing wrong, but it may be as mentioned by Stuart below.
|
|
|
|
|
yesh i resloved the issue.
it is due to file is generated by windows
so it contain /r/n so now i created file in unix system , now it resolved my issue. but how we handle such situation
|
|
|
|
|
Add something straight after the getline call to remove a trailing \r? Like this:
if (*data_string.rbegin() == '\r')
data_string.erase(data_string.length()-1);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hint - you haven't got ls in your map!!!! You've got dir , which is the WIndows equivalent, but not ls .
When you add
ls,/code>, it works. I know, I've just run it on OS X, which is a Unix... <br />
<br />
<div class="ForumSig">Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p</div>
|
|
|
|
|
When we create an owner draw Listbox, We override DrawItem() and MeasureItem(). But this just draw item for Listbox. How to draw border for ListBox?
|
|
|
|
|
You mean you want to draw a custom border around your list control? If so, try handling the WM_NCPAINT[^] message.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I wrote a Queue class in java with the method Add
public void add ( Object x )<br />
{<br />
items[rear] = x;<br />
rear = (rear + 1) % items.length;<br />
++count;<br />
}<br />
Now I'm trying to write it in C++. My problem here is I can't use rear = (rear + 1) % items.length;
Since I can't use items.length, what would that be equivalent to in C++?
Thanks in advance,
Jonig
|
|
|
|
|
You'd keep track of the allocated length of items yourself. (Yes, it's annoying that you can't get the allocated length in C++, even though it's available to library code.)
|
|
|
|
|
Or use any standard containers like std::vector rather than plain arrays.
|
|
|
|
|
Use the STL deque[^]
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
If you just want to use a queue, then the STL already has one[^].
If you're doing this for a learning experience, then the first thing to learn is that C/C++ arrays a) are not easily resizable and b) do not track their own length. If you want to do this with arrays, then you'll need to reallocate arrays when they get too small (remembering to copy all the elements to the newly resized array) and also keep track of the number of allocated and used array elements. Or you could use an STL container like a vector in place of the array.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi
I have a MDI application. How can I get the number of the "CMDIChildWnd" initialized?
Thanks
|
|
|
|
|
|
Hi all,
I am wondering if we can get sourcecode information when an exception occurs. I understand we need debug symbols to get actual source file and line number, but is there a way I can get a unique identifiers that describe the source file and linenumbers where the crash occured - somethng from the dissembly of the callstack? Microsoft must be doing this internally, but is this information available for external developers? Your help is very much appreciated.
Nachiket
|
|
|
|
|
Well, unfortunately if your using Visual Studio 2005 or higher then you need to parse the PDB to obtain the line number in a Release build. Unless you want to add __LINE__ macros[^] all over your code...
This may help:
Retrieving Symbol Information by Address[^]
If you are using Visual Studio 2003 or below you can use the /MAPINFO:LINES linker option. This will create a MAP file which contains symbolic names, address offsets and even line numbers at the bottom. When an exception occurs all you needed to do was walk the list of line numbers and compare the address of the exception to the ones in the list.
I dont really know why they removed the /MAPINFO:LINES option but I suspect it has something to do with VS2005 optimizations.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks David. That was really helpful information.
|
|
|
|
|
Hello. I'm writing a program using M$ Visual C++. Is there a simple API for getting the file size? Something like GetFileSize? I'm trying to read out bytes from a binary file, and I think it's prematurely reading out an EOF character. So, I need to query the filesize from the OS. Thanks.
|
|
|
|
|
pcpro178 wrote: Is there a simple API for getting the file size? Something like GetFileSize?
You mean something like GetFileSize()[^]? Yeah, there is.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|