How do I split a String and keep the delimiters?

C++ statistics project?

  • I have just done a small statistics displaying program for a small past time project. However just coudn't get it to compile anything missing, I suspect its the declarations. #include <iostream> #include <string> using namespace std; int main; const int ORE_PIECES = 500; int soldiers, KIA, survivors; string commander; //get the information cout << "Welcome to Combat Statistics\n\n"; cout << "Plese enter the following for personalised combat exterince\n"; cout << "Enter a number"; cin >> "soldiers"; cout << "Enter a number, lower than the first: "; cin >> KIA; survivors = soldiers - KIA; cout << "Enter your last name: "; cin >> commander; //tell the story cout << "\nA able squad of " << soldiers << " set out on a mission "; cout << "-- in search of the lost ore of the enemy. "; cout << "The squad was led by the legendary commander, " << commander << ".\n"; cout << "\nAlong the way, a band of guns wielding militants ambushed the squad. "; cout << "All squad members fough courageously under the command of " << commander; cout << ", and the militants were killed, but at a cost. "; cout << "Of the soldiers, " << KIA << " were declared eliminated, "; cout << "leaving just " << survivors << " in the squad.\n"; cout << "\nThe squad was about to give up all hope "; cout << "But whilwe laying the deceased to rest, "; cout << "they stumbled upon the lost ore. "; cout << "So the adventurers split " << ORE_PIECES << " ore pieces."; cout << commander << " held on the extra " << (ORE_PIECES % survivors); cout << " pieces to keep things fair of course.\n"; return 0; }

  • Answer:

    you had couple of syntax errors corrected now . main should not have ; after and soldiers is a variable so you dont need to put it between "" #include <iostream> #include <string> using namespace std; main() { const int ORE_PIECES = 500; int soldiers, KIA, survivors; string commander; //get the information cout << "Welcome to Combat Statistics\n\n"; cout << "Plese enter the following for personalised combat exterince\n"; cout << "Enter a number"; cin >> soldiers; cout << "Enter a number, lower than the first: "; cin >> KIA; survivors = soldiers - KIA; cout << "Enter your last name: "; cin >> commander; //tell the story cout << "\nA able squad of " << soldiers << " set out on a mission "; cout << "-- in search of the lost ore of the enemy. "; cout << "The squad was led by the legendary commander, " << commander << ".\n"; cout << "\nAlong the way, a band of guns wielding militants ambushed the squad. "; cout << "All squad members fough courageously under the command of " << commander; cout << ", and the militants were killed, but at a cost. "; cout << "Of the soldiers, " << KIA << " were declared eliminated, "; cout << "leaving just " << survivors << " in the squad.\n"; cout << "\nThe squad was about to give up all hope "; cout << "But whilwe laying the deceased to rest, "; cout << "they stumbled upon the lost ore. "; cout << "So the adventurers split " << ORE_PIECES << " ore pieces."; cout << commander << " held on the extra " << (ORE_PIECES % survivors); cout << " pieces to keep things fair of course.\n"; return 0; }

StanZero at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.