开发者

How to put Char** into _stprintf

开发者 https://www.devze.com 2023-01-14 16:31 出处:网络
I have this code. I would like to put argv[1] as prefix to fileName. How do I do that? int _tmain(int argc, char** argv)

I have this code. I would like to put argv[1] as prefix to fileName. How do I do that?

int _tmain(int argc, char** argv)
{
...
    _stprintf(fileName, _T("%04d-%02d-%02d-%02d-%02d-%02d-%03d.jpeg"), lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.开发者_Go百科wMinute, lt.wSecond, lt.wMilliseconds);


_stprintf(fileName, _T("%s-%04d-%02d-%02d-%02d-%02d-%02d-%03d.jpeg"), argv[1], lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);

That will do what you want, but since you're using C++ you would be best to use a stringstream instead.

#include <stringstream>

int main(int argc, char** argv)
{
    std::stringstream ss;
    ss << argv[1] << "-" << lt.wYear << "-" << lt.wMonth << "-" << lt.wDay << "-" << lt.wHour << "-" << lt.wMinute << "-" << lt.wSecond << "-" << lt.wMilliseconds << ".jpeg";
}

You can then access the string with ss.str(). You can also use the same stream format modifiers you would use with any output stream.


Assuming that the wholly non-standard _stprintf() is closely related to sprintf(), then:

  • Use %s at the point in the format string where the name goes.
  • Pass argv[1] at the corresponding point in the argument list.

Note that argv has the type char **; therefore, argv[1] has the type char *.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号