Hi all,
Having several strings how do I construct variable to pass to
system():
Lets say the date command
string str = "14/10/08 19:06:09";
strDD = str.substr(0,2) ;
strMM = str.substr(3,2) ;
strYY = str.substr(6,2) ;
strhh = str.substr(9,2) ;
strmm = str.substr(12,2 );
strss = str.substr(15,2 );
strT<<"date -u "<<strMM<<strDD <<strhh<<strmm< <strYY<<"."<<st rss<< "
2>&1 >/dev/null;"<<endl;
system(strT);
when I compile it throws
rtchk.cpp: In function `int main (int, char **)':
rtchk.cpp:59: no match for `string & << const char[9]'
so i could be a syntax error, but I'm newbie.
if there is a typo, I can't see it. 10 1822
Atropo wrote:
Hi all,
What's wrong with the answer I gave last time you asked?
--
Ian Collins
On 15 oct, 17:54, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote:
Hi all,
What's wrong with the answer I gave last time you asked?
--
Ian Collins
Sorry Ian. I though those post were deleted after hours refreshing
the webpage this post never shows..
Atropo wrote:
On 15 oct, 17:54, Ian Collins <ian-n...@hotmail.co mwrote:
>Atropo wrote:
>>Hi all,
What's wrong with the answer I gave last time you asked?
*Please* don't quote signatures.
>
Sorry Ian. I though those post were deleted after hours refreshing
the webpage this post never shows..
Usenet isn't IM, you have to give messages time to propagate. That
dreadful google interface appears to make things worse.
--
Ian Collins
On 15 oct, 19:25, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote:
On 15 oct, 17:54, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote: Hi all,
What's wrong with the answer I gave last time you asked?
*Please* don't quote signatures.
Again sorry, but I don't understand what you mean.
>
Sorry Ian. *I though those post were deleted * after hours refreshing
the webpage this post never shows..
Usenet isn't IM, you have to give messages time to propagate. *That
dreadful google interface appears to make things worse.
Yo're absolutely right. but I'm RTFM.
about my issue, you told me on the other similar post to use
ostringstream. I'm reading but it gets more confusing to me. would
you please could give me an example on how to prepare the system call
with those strings
--
Ian Collins
Atropo wrote:
On 15 oct, 19:25, Ian Collins <ian-n...@hotmail.co mwrote:
>Atropo wrote:
>>On 15 oct, 17:54, Ian Collins <ian-n...@hotmail.co mwrote: Atropo wrote: Hi all, What's wrong with the answer I gave last time you asked?
*Please* don't quote signatures.
Again sorry, but I don't understand what you mean.
Google does.
about my issue, you told me on the other similar post to use
ostringstream. I'm reading but it gets more confusing to me. would
you please could give me an example on how to prepare the system call
with those strings
std::ostringstr eam out;
out << whatever;
system( out.str().c_str () );
>-- Ian Collins
This is a signature.
--
Ian Collins
On 15 oct, 19:52, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote:
On 15 oct, 19:25, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote: On 15 oct, 17:54, Ian Collins <ian-n...@hotmail.co mwrote: Atropo wrote: Hi all, What's wrong with the answer I gave last time you asked?
*Please* don't quote signatures.
Again sorry, but I don't understand what you mean.
Google does.
about my issue, you told me on the other similar post to use
ostringstream. I'm reading but it gets more confusing to me. * would
you please could give me an example on how to prepare the system call
with those strings
std::ostringstr eam out;
out << whatever;
system( out.str().c_str () );
--
Ian Collins
This is a signature.
--
Ian Collins
Thanks Ian. as I told you I'm on the very beginnings of c++. I
included your code but compiler throws error about not function
osstringstream defined. what library do i need to include??
meanwhile kept the string var, now it doesn't complaint about
asignation and the cout shows well what i want, but not the system
call. do i need to include something on the system call
strt ="date -u "+ strMM+ strDD+ strhh+ strmm+ strAA+ "." + strss +
" 2>&1 >/dev/null;";
cout << strt;
system(strt);
rtchk2.cpp:62: cannot convert `string' to `const char *' for argument
`1' to `system (const char *)'
maybe something like the example you gave me.
system( out.str().c_str () )
in this case you defined out, but to use it you put out.str().c_str ()
is there something similar for the strings ??
Atropo wrote:
On 15 oct, 19:52, Ian Collins <ian-n...@hotmail.co mwrote:
>std::ostringst ream out;
out << whatever;
system( out.str().c_str () );
*Please* stop quoting signatures!
>
Thanks Ian. as I told you I'm on the very beginnings of c++. I
included your code but compiler throws error about not function
osstringstream defined. what library do i need to include??
You don't include a library, you include a header. osstringstream ind
declared in <sstream>.
Your C++ book should have told you this, which one are you using?
meanwhile kept the string var, now it doesn't complaint about
asignation and the cout shows well what i want, but not the system
call. do i need to include something on the system call
strt ="date -u "+ strMM+ strDD+ strhh+ strmm+ strAA+ "." + strss +
" 2>&1 >/dev/null;";
cout << strt;
system(strt);
Well that's not surprising, is it? You changed the operator.
rtchk2.cpp:62: cannot convert `string' to `const char *' for argument
`1' to `system (const char *)'
Very true. Look up std::string's c_str() method. Look up what
std::osstringst ream's str() method returns.
You should do some background reading on strings and iostreams.
--
Ian Collins
On Wed, 15 Oct 2008 19:16:51 -0700 (PDT), Atropo <lx*******@gmai l.com>
wrote:
>On 15 oct, 19:52, Ian Collins <ian-n...@hotmail.co mwrote:
>system( out.str().c_str () );
....
> system(strt);
Ian already provided the answer, really. The .str () method for
ostringstream gives a string, but he needed to use .c_str () as well
before calling system.
Even though you're accessing your string directly, you also need the
..c_str ()
system(strt.c_s tr ());
It's a bit of C heritage. There are two styles of strings - char
arrays and the string class. The system call needs a char array (or
rather a pointer to one).
The string class is definitely the thing to use when you can, but
sometimes you can't avoid the char arrays.
On 15 oct, 21:28, Ian Collins <ian-n...@hotmail.co mwrote:
Atropo wrote:
On 15 oct, 19:52, Ian Collins <ian-n...@hotmail.co mwrote:
std::ostringstr eam out;
out << whatever;
system( out.str().c_str () );
*Please* stop quoting signatures!
Thanks Ian. *as I told you I'm on the very beginnings of c++. *I
included your code but compiler throws error about not function
osstringstream defined. * what library do i need to include??
You don't include a library, you include a header. *osstringstream ind
declared in <sstream>.
Your C++ book should have told you this, which one are you using?
Actually dont have any. which one would you recommend me?? for free
download of course, maybe you realize by my bad english that english
is not my primary languaje
>
meanwhile kept the string var, now it doesn't complaint about
asignation and the cout shows well what i want, but not the system
call. do i need to include something on the system call
* *strt ="date -u "+ strMM+ strDD+ strhh+ strmm+ strAA+ "." + strss +
* * * * * *" 2>&1 >/dev/null;";
* *cout << strt;
* *system(strt);
Well that's not surprising, is it? *You changed the operator.
Well I just use somes examples to twist a bit.
>
rtchk2.cpp:62: cannot convert `string' to `const char *' for argument
`1' to `system (const char *)'
Very true. *Look up std::string's c_str() method. *Look up what
std::osstringst ream's str() method returns.
very useful tip, I'm RTFM
I'll give a try to system( strt.c_str() ); I'm just guessing here.
>
You should do some background reading on strings and iostreams.
I know , but when you know nothing, usually don't know what to look
for.
--
Ian Collins
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: phpfrizzle |
last post by:
Hi there, this might sound strange,
but i need to construct a name of a variable:
i have these vars (and loads more):
$menu_ho = massageMe("$string_1");
$menu_do = massageMe("$string_2");
$menu_co = massageMe("$string_3");
they stand for some massaged strings, which are
displayed as a body title.
|
by: Laser Lu |
last post by:
Hello, everybody,
do you know how to use this Grouping Construct?
(?> )
I've found its reference on MSDN, but still can not understand it totally.
The following is its description:
Nonbacktracking subexpression (also known as a "greedy" subexpression). The
subexpression is fully matched once, and then does not participate piecemeal
|
by: Ioannis Vranos |
last post by:
In .NET (and C++/CLI) there is an overloaded String == operator for
handles. That is when we do comparison of two String handles the
contents of the Strings are compared instead of their addresses.
However how can we do a handle comparison when we want to determine if
we have to do with the same object?
In the style
|
by: Ninan |
last post by:
I have different 256 character length records stored in a file. The
first character is the record identifier. I want to instantiate
different record objects. I cannot change the records stored in file as
it comes from a third party standard. I am planning to use the factory
method to create the objects.
Is there a faster way to construct this class other than the obvious
solution I am presenting below
class Record {
|
by: sheephead86 |
last post by:
Hi,
I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing in the right direction.
Ok the problem.
I am creating a program that ask the user to input a height value, the program will then do a calculation and create a golden ratio width. The type of both the height and the width are double.
This is...
| |
by: kamikaze04 |
last post by:
Hello.
I have a very newbie question about Streams. The situation is that i have a function (that i cannot modify it's definition/call):
public void F1(istream & in){
while( ...) {
in >> value
do stuff with value;
}
|
by: Madmartigan |
last post by:
Hi
I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way.
I have included my code thus far and at this stage would like to know how I can get the RandomWordManager, which I found on another site, to display a newly generated word as the textBox1 text when the user enters a new game.
I have enclosed tags around the two forms I have...
|
by: damiensawyer |
last post by:
Hi,
Can someone please explain to me something about delegates?
My understanding is as follows. A delegate is basically an object that
can hold a reference to a "method" somewhere. That is, it's
essentially a pointer to a piece of code somewhere else in memory.
It therefore (to me anyway) makes sense to define delegates with their
signatures and be able to use those signatures at different points in
|
by: Atropo |
last post by:
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);
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |