user1065969
user1065969

Reputation: 599

echo command using c++

I want to issue the echo command inside a c++ file.

All i need to do is

echo "xml::/var/some.xml" >> /var/config

In C++ file, I tried,

system("echo" + "xml::/var/some.xml" +">> /var/config");

But it throws invalid operands of types const char[6] and const char[46] to binary operator +.

Need help

Upvotes: 2

Views: 25100

Answers (3)

ds1848
ds1848

Reputation: 172

Try

#include <string>
system(std::string("echo" + "xml::/var/some.xml" +">> /var/config").cstr())

you are passing raw character strings which do not support the + operator -- so try to use std::string instead.

Upvotes: -2

Jerry Coffin
Jerry Coffin

Reputation: 490663

I guess this is one where you may be able to get away with "can has codez?":

#include <iostream> 
#include <iterator>
#include <algorithm>

int main(int argc, char **argv) { 

   std::copy(argv+1, argv+argc, std::ostream_iterator<char *>(std::cout, ""));
   return 0;
}

Upvotes: 3

Brendan
Brendan

Reputation: 3493

You could just output the data yourself using stdio methods fopen/fputs/etc..

http://linux.die.net/man/3/fputs

Upvotes: 1

Related Questions