473,396 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SWIG std::string& passing

Hello,

I have been trying to get this simple call to work with a SWIG
interface. The problem is I do not know how to pass a const char * or a
std::string & in python to SWIG wrapped code. I tried several of the
*.i libraries at http://www.swig.org/Doc1.3/Library.html. Most notably
the "std_string.i" And get the following:
w.SetDestFilename("test.bmp")

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/soa/dev/users/reder/Dshell++Pkg-reder01/lib/PYTHON/Dspace/Dnoise_Py.py",
line 1340, in SetDestFilename
def SetDestFilename(*args): return
_Dnoise_Py.WriterBMP_SetDestFilename(*args)
TypeError: argument number 2: a 'std::string *' is expected,
'str(test.bmp)' is received

The C++ method is:

void WriterBMP::SetDestFilename (const std::string& filename)

This should be easy to pass the filename to? Do you have an example?
What do I add to the *.i file?

Thanks for any and all replies,

Len

--
===================================
Leonard J. Reder
Home office email : re***@ieee.org
Lab email : re***@jpl.nasa.gov
Lab web page : http://reder.jpl.nasa.gov
===================================
--
===================================
Leonard J. Reder
Home office email : re***@ieee.org
Lab email : re***@jpl.nasa.gov
Lab web page : http://reder.jpl.nasa.gov
===================================
Jul 19 '05 #1
1 5286
Add the line

%include stl.i

to your .i file. This will make other stl containers available, in
addition to string. Make sure you put this line before any include
directives for classes that use std::string. SWIG requires classes to
be declared before they are used in order for the interfaces to be
exposed completely.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: KidLogik | last post by:
Hello! I am using std::stringstream && std::string to parse a text file -> std::ifstream in; std::string s; std::streamstring ss; int n; I grab each line like so -> std::getline(in,s);
15
by: roberts.noah | last post by:
Are there any decent benchmarks of the difference between using c strings and std::string out there? Google isn't being friendly about it. Obviously this would be dependant on different...
2
by: zhege | last post by:
I am a beginner of C++; I have a question about the std:string and std:cout class; Two pieces of code: -------------------------------- #include <iostream> #include <string> using namespace...
2
by: pookiebearbottom | last post by:
Just looking for opinion on which of the 3 methods below people use in their code when they convert a 'const char *' to a 'const std::string &' came across #3 in someone's code and I had to...
3
by: sernamar | last post by:
Hi, I have the following base class class UnitOfMeasure { public: //... std::string& GetName() {return _uomName;}; //... protected:
1
by: gabriel.becedillas | last post by:
I have a lot of functions returning "const std::string&". Every time I wrap one of those I have to do it like this: class_.def("name", &someclass::bla,...
0
by: Amitabh Saikia | last post by:
Hi I have created a simple function called 'addTheString(string& str, string appstr)' and the intension is to append the 'appstr' to 'str' and use 'str'. I tried swigging this method. My...
2
by: ragged_hippy | last post by:
Hi, If I have a method that has string reference as a parameter, what happens if I pass a const char* variable to this method? One thought is that a temporary string will be created in the...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.