NEWBIE:如何粘贴字符串来为system()发出命令 [英] NEWBIE: how to paste strings to make a command for system()
问题描述
大家好。
如果有几个字符串,我如何将它们组合起来构建命令;
可以说运行date命令。
string str =" 14/10/08 19:06:09" ;;
strDD = str.substr(0,2);
strMM = str.substr(3,2);
strAA = str.substr(6,2);
strhh = str.substr(9,2) );
strmm = str.substr(12,2);
strss = str.substr(15,2);
strtarget<<" date -u"<< strMM<<< strDD<< strhh<< strmm<< strAA<<"。"<< str ss<< ;
" 2>& 1 / dev / null;"<< endl;
system(strtarget);
不确定是否问题是它在strtarget行中的语法(59)。当
我编译我得到这个
rtchk.cpp:在函数`int main(int,char **)'':
rtchk.cpp:59:不匹配`string& << const char [9]''
提前致谢非常感谢任何建议。
Atropo写道:
嗨所有。
有几个字符串我如何组合它们来构造一个命令;
让我们说运行日期命令。
>
string str =" 14/10/08 19:06:09" ;;
strDD = str.substr(0,2);
strMM = str.substr(3,2);
strAA = str.substr(6,2);
strhh = str.substr(9,2);
strmm = str.substr(12,2);
strss = str.substr(15,2);
strtarget< <" date -u"<<< strMM<< strDD<< strhh<<< strmm<<< strAA<<"。"<< str ss<<
" 2>& 1 / dev / null;"<< endl;
system(strtarget);
不确定是否问题是它在strtarget行中的语法(59)。当
我编译我得到这个
rtchk.cpp:在函数`int main(int,char **)'':
rtchk.cpp:59:不匹配`string& << const char [9]''
提前致谢非常感谢任何建议。
std :: string(我假设您使用的是std :: string?)没有
运算符<<。
您应该使用ostringstream。
-
Ian Collins
15月15日17:22,Ian Collins< ian-n ... @ hotmail.comwrote:
Atropo写道:
大家好。
有几个字符串我如何组合它们来构造一个命令;
让我们说运行date命令。
* * * * string str * =" 14/10/08 19:06:09" ;;
* * strDD = str.substr(0,2);
* * strMM = str.substr(3,2);
* * strAA = str.substr( 6,2);
* * strhh = str.substr(9,2);
* * strmm = str.substr(12,2);
* * strss = str.substr(15,2);
strtarget<<"日期-u"<< strMM<< strDD<< strhh<< strmm<< ; strAA<<"。"<<&s;<<<
" 2>& 1 / dev / null;"<< endl;
* * * * system(strtarget);
不确定问题是strtarget行中的语法(59)。 *当
我编译我得到这个
rtchk.cpp:在函数`int main(int,char **) )'':
rtchk.cpp:59:不匹配`string& << const char [9]''
提前致谢。 *非常感谢任何建议。
std :: string(我假设您使用的是std :: string?)*没有
运算符<< 。
你应该使用ostringstream。
-
Ian Collins- Ocultar texto de la cita -
- Mostrar texto de la cita -
对不起Ian但我真的是新手。我该如何使用
ostringstream?
Atropo写道:
>
对不起伊恩,但我真的是新手。我该如何使用
ostringstream?
与使用任何其他ostream的方式相同,例如std :: cout。在你的
的情况下,用ostringstream替换你想要流式传输的字符串。
查看如何使用str()方法获取缓冲区的字符串。
-
Ian Collins
Hi all.
Having several strings how do i combine them to construct a command;
lets say to run the date command.
string str = "14/10/08 19:06:09";
strDD = str.substr(0,2);
strMM = str.substr(3,2);
strAA = str.substr(6,2);
strhh = str.substr(9,2);
strmm = str.substr(12,2);
strss = str.substr(15,2);
strtarget<<"date -u "<<strMM<<strDD<<strhh<<strmm<<strAA<<"."<<str ss<<
" 2>&1 /dev/null;"<<endl;
system(strtarget);
Not sure if the problem it''s syntax in the strtarget line (59). when
I compile i get this
rtchk.cpp: In function `int main (int, char **)'':
rtchk.cpp:59: no match for `string & << const char[9]''
Thanks in advance. really appreciate any advise.
Atropo wrote:Hi all.
Having several strings how do i combine them to construct a command;
lets say to run the date command.
string str = "14/10/08 19:06:09";
strDD = str.substr(0,2);
strMM = str.substr(3,2);
strAA = str.substr(6,2);
strhh = str.substr(9,2);
strmm = str.substr(12,2);
strss = str.substr(15,2);
strtarget<<"date -u "<<strMM<<strDD<<strhh<<strmm<<strAA<<"."<<str ss<<
" 2>&1 /dev/null;"<<endl;
system(strtarget);
Not sure if the problem it''s syntax in the strtarget line (59). when
I compile i get this
rtchk.cpp: In function `int main (int, char **)'':
rtchk.cpp:59: no match for `string & << const char[9]''
Thanks in advance. really appreciate any advise.
std::string (I assume you are using std::string?) does not have an
operator <<.
You should be using an ostringstream.
--
Ian Collins
On 15 oct, 17:22, Ian Collins <ian-n...@hotmail.comwrote:Atropo wrote:Hi all.
Having several strings how do i combine them to construct a command;
lets say to run the date command.
* * * *string str * = "14/10/08 19:06:09";
* *strDD = str.substr(0,2);
* *strMM = str.substr(3,2);
* *strAA = str.substr(6,2);
* *strhh = str.substr(9,2);
* *strmm = str.substr(12,2);
* *strss = str.substr(15,2);
strtarget<<"date -u "<<strMM<<strDD<<strhh<<strmm<<strAA<<"."<<str ss<<
" 2>&1 /dev/null;"<<endl;
* * * * system(strtarget);
Not sure if the problem it''s syntax in the strtarget line (59). *when
I compile i get this
rtchk.cpp: In function `int main (int, char **)'':
rtchk.cpp:59: no match for `string & << const char[9]''
Thanks in advance. *really appreciate any advise.
std::string (I assume you are using std::string?) *does not have an
operator <<.
You should be using an ostringstream.
--
Ian Collins- Ocultar texto de la cita -
- Mostrar texto de la cita -sorry Ian but I''m a really newbie. how should I use the
ostringstream ??
Atropo wrote:>
sorry Ian but I''m a really newbie. how should I use the
ostringstream ??The same way as you use any other ostream, such as std::cout. In your
case, replace the string you were trying to stream to with an ostringstream.
Look up how to use the str() method to get the buffer''s string.
--
Ian Collins
这篇关于NEWBIE:如何粘贴字符串来为system()发出命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!