Answer to Question #38928 in C++ for nico

Question #38928
I'm new in C++ and have a question about how to use a variable (pathLed) that carries a path in the fs.open function? String seams not to work. If I use define pathLed "/sys/class/leds/beaglebone:green:usr0" it works, but I need a variable to sign different paths to pathLed. Thanks for the answer. Nico

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string pathLed = "/sys/class/leds/beaglebone:green:usr0";

fs.open (pathLed "/trigger", std::fstream::out);
fs << "none";
fs.close();
1
Expert's answer
2014-02-19T11:25:54-0500
Dear customer, please try this:
fs.open (pathLed.c_str(), std::fstream::out);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS