PDA

View Full Version : problem in calling string function



ramin.lich
27th December 2014, 22:44
Hi,
here is my code

string cmdCommand(const string &command){
fstream file("temp.txt");
file.close();
string cmd=command+ "> temp.txt";
file.open("temp.txt");
stringstream buffer;
buffer << file.rdbuf();
file.close();
return buffer.str();

try{
result= cmdCommand("ping google.com");
}
catch(const char* exc)
{
cout<<exc;
}

}

void MainWindow::on_pushButton_clicked()
{
cmdCommand();
ui->textBrowser->setText(QString::fromStdString(result));
}


when i compile this code this error shows:
error: too few arguments to function 'std::string cmdCommand(const string&)'
cmdCommand();
^
thanks :)

anda_skoa
28th December 2014, 00:58
The compiler already told you what the problem is, no?

Cheers,
_

d_stranz
28th December 2014, 01:28
That "return buffer.str();" on line 9 is going to make it really difficult to execute any of the code that comes after it. If you do remove it, then Google is going to be really annoyed when you recursively ping it a million or so times until your call stack overflows.

And if you still don't understand what the error is in your code, compare lines 1 and 23 and see if you can spot the difference.

martin72
28th December 2014, 08:24
Your method cmdCommand(const string &command) expects a string as argument while in line 23 you call this method with cmdCommand(); so without a string argument.