Add string type to project

How add string variable to project? file Plane.h
I tried
#include <string>
std::string str;
but error appear.
Can I add c++ string to project?
Help please. Thanks!

1 Like

If you do not tell the exact error message, how do you expect us to help? Telepathy?? :slight_smile:

In file included from ā€¦/ā€¦/ArduPlane/mode_loiter.cpp:2:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/RC_Channel.cpp:1:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/mode_guided.cpp:2:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/altitude.cpp:16:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/tiltrotor.cpp:1:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/mode_thermal.cpp:2:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/avoidance_adsb.cpp:3:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

In file included from ā€¦/ā€¦/ArduPlane/mode_acro.cpp:2:0:
ā€¦/ā€¦/ArduPlane/Plane.h:178:2: error: ā€˜stringā€™ does not name a type
string tail = ā€œasddā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/andre/ardupilot/build/CUAV-X7ā€™
Build failed
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291275848: cxx mode_loiter.cpp -> mode_loiter.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145289677736: cxx RC_Channel.cpp -> RC_Channel.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291275288: cxx mode_guided.cpp -> mode_guided.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145289677848: cxx altitude.cpp -> altitude.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145288751144: cxx tiltrotor.cpp -> tiltrotor.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145288749464: cxx mode_thermal.cpp -> mode_thermal.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291273720: cxx avoidance_adsb.cpp -> avoidance_adsb.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291274728: cxx mode_acro.cpp -> mode_acro.cpp.34.o}
(run with -v to display more information)

simple :
std::string test = ā€œplopā€;

But it doesnā€™t work. I tried the same. I donā€™t unferstand why Ardupilot doesnā€™t work with string

In file included from ā€¦/ā€¦/ArduPlane/Attitude.cpp:1:0:
ā€¦/ā€¦/ArduPlane/Plane.h:179:7: error: ā€˜stringā€™ in namespace ā€˜stdā€™ does not name a type
std::string test = ā€œplopā€;
^~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/andre/ardupilot/build/CUAV-X7ā€™
Build failed
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291171992: cxx mode_loiter.cpp -> mode_loiter.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291186808: cxx servos.cpp -> servos.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145293299608: cxx avoidance_adsb.cpp -> avoidance_adsb.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145293299160: cxx Plane.cpp -> Plane.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291187256: cxx takeoff.cpp -> takeoff.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145293298712: cxx GCS_Mavlink.cpp -> GCS_Mavlink.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145291187144: cxx tailsitter.cpp -> tailsitter.cpp.34.o}
(run with -v to display more information)
-> task in ā€˜bin/arduplaneā€™ failed (exit status 1):
{task 123145293298040: cxx Attitude.cpp -> Attitude.cpp.34.o}
(run with -v to display more information)

I need to use some strings variables. How to use strings in Ardupilot correctly?
I tried #include <string>, std::string, string.h, cstring, but donā€™t work. donā€™t build. Thanks

https://ardupilot.org/dev/docs/style-guide.html#no-standard-library

3 Likes

Iā€™ve had been struggling with the same problem. Your comment helped me a lot. To whom it might concern:

For efficiency reasons, ArduPilot doesnā€™t use the C standard library (std::). We also prefer to use functions which are consistent across platforms to ease support (not using 64-bit maths on platforms that support it is useful, for example).

This means no std::vector, no std::string and no std::unordered_map, for example.

1 Like