How do I pass String.Concat "/" [""; "usr"; "local"; "bin"] to c?

Asked

Viewed 52 times

1

I know a lot of things in c, but this is new to me, but, see below with Ocaml: Generating a component file name: Note that the second argument is a list of strings.

  • String.Concat "/" [""; "usr"; "local"; "bin"]

It is very simple and easy to use. This generates as output ....

  • : string = "/usr/local/bin"

How can I transfer this to c? I wanted to understand how to do this in c!

I wanted to use this with: Document.write() with a printf.

Footsteps:

The program inserts:

  • String.Concat "/" [""; "usr"; "local"; "bin"]

Gera:

  • : string = "/usr/local/bin"

And then gives a:

  • Document.write()

And then it turns:

  • Document.write("/usr/local/bin");

And then in:

  • printf.

What I want with it?

  • I want to create a directory! And so insert files or data in this directory!

Because Document.write(); ?

  • Is that I want to insert this directory in the document and reference - lo.

Because printf?

  • Why printf does a real Document.write() by writing in a data file.
  • Could be in C++?

  • Yes can be done in c++. That would help a lot! You could do, if yes: - show me, PLEASE.

  • Don’t post comments like answers.

1 answer

0

This is a solution without many validations:

#include <string>
#include <vector>
#include <numeric>
using namespace std;


class String
{
public:
    string concat ( const string val)
    {
        vector _tokens;
        string delimiters(" \"\';[]"); 

        Tokenize ( string(val), _tokens, delimiters);
        vector::iterator iv = _tokens.begin();

        for(int i=2; i < _tokens.size(); i++)
        {
            _tokens[i] = _tokens[0] + _tokens[i];
        }

        return accumulate(_tokens.begin(), _tokens.end(), string(""));;
    }

private:
    void Tokenize(const string & str,
                  vector & tokens,
                  const string & delimiters = " ")
    {
        // Skip delimiters at beginning.
        string::size_type lastPos = str.find_first_not_of(delimiters, 0);
        // Find first "non-delimiter".
        string::size_type pos     = str.find_first_of(delimiters, lastPos);

        while (string::npos != pos || string::npos != lastPos)
        {
            // Found a token, add it to the vector.
            tokens.push_back(str.substr(lastPos, pos - lastPos));
            // Skip delimiters.  Note the "not_of"
            lastPos = str.find_first_not_of(delimiters, pos);
            // Find next "non-delimiter"
            pos = str.find_first_of(delimiters, lastPos);
        }
    }
};

int main(int argc, _TCHAR* argv[])
{
    String MyString;

    string path = MyString.concat("\"/\" [\"\"; \"usr\"; \"local\"; \"bin\"]" );

    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.