Hello everyone, I am having a slight problem with my program, and that is that It just doesn't seem to be working! I would like someone to help me fix it, because I can't do It myself. The main problem I am having is adding a string to a string,
example:

string data;
string input;
cin>>input;
data + "\n"input;

I know I must be doing something terribly wrong, I can just tell, but no other website has been able to help me!
Here's the sorce of the program I need help with, please be honest and don't pass it off as your own. The idea of the program is to allow a user to test their IP using some basic comands. Please don't write someting here about how dumb an Idea this program is, because all I'm trying to do Is get a little bit of programming practice.
Anyway, here's the code:

#include <iostream>

using namespace std;

//Startup Voids
void error_check();
void return_error();
void generate_command();
bool test_command();
//Errors
bool error;
bool done = false;
string command;
string fails;
//general

int main()
{
	cout<<"Starting up..."<<endl;
	error_check();
	cout<<"Testing IP..."<<endl;
	system("ipconfig");
	cout<<"Connected!"<<endl;
	system("cls");

}
void error_check()
{
	cout<<"Checking for errors..."<<endl;
	cout<<"Running error checks on commands:"<<endl;
	while(done == false)
	{
		cout<<"Currently checking :"<<command<<endl;
		test_command();
		if(test_command == true)
		{
			cout<<"Failed"<<endl;
			fails + "\n "command;
		}

}
void return_error()
{
	if(error == true)
	{
		cout<<"***********************************"<<endl;
		cout<<"*                                 *"<<endl;
		cout<<"*  *****  ***   ***    **   ***   *"<<endl;
		cout<<"*  *      *  *  *  *  *  *  *  *  *"<<endl;
		cout<<"*  *****  ***   ***   *  *  ***   *"<<endl;
		cout<<"*  *      * *   * *   *  *  * *   *"<<endl;
		cout<<"*  *****  *  *  *  *   **   *  *  *"<<endl;
		cout<<"*                                 *"<<endl;
		cout<<"***********************************"<<endl;
		cout<<endl;
		}
	}
}
bool test_command()
{
}

I'll update the code If I happen to make any more progress.
Thanks alot,
TailsTheFox

  • You need to include <string> to use the std::string class.
  • Your while loop in error_check is missing a closing brace.
  • if(test_command == true) should be if(test_command() == true) . Otherwise you're comparing a pointer to a function against true. You can also remove the == true part because it's implicit:
    if (test_command())
  • fails + "\n "command needs a concatenation operator between each string, and the result should be assigned back to fails:
    fails = fails + "\n " + command;
  • You have a rogue closing brace in the if statement of return_error.
  • test_command has to return a value. If it's currently a stub, false is a good default.

if(test_command == true) should be if(test_command() == true) .

Yes. But there's another subtle point here that is worth mentioning.

It is generally a bad idea to write expressions of the form function() == true . It is harmless to do so if the function returns a bool value, as test_command does in this case; but it is not unusual for C++ functions to return integers with the intent that zero be taken as false and any other value be taken as true.

If you use such a function in an expression of the form function() == true , the effect will be to take the value 1 as true and anything else as false, which is probably not what you wanted.

In the context of an if or while, the best solution is to drop the comparison; if(function()) does exactly what you want. Alternatively, function() != false is safe, and means the same as function() != 0 .

Of course, in all cases, you need parentheses to call a function.

Edited 5 Years Ago by arkoenig: fix typos

This article has been dead for over six months. Start a new discussion instead.