0

I cant get this program to compile. I get an error by the auto start and auto end. That there is no name a type. Also am trying to get findword and findchar in this program to work. Any advice will be greatly appreciated.

#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main(int argc, const char * argv[]) {

    string allWords;

    int lineCharacterCount = 0;

    int maxCharacterCount = 60;

    int charactersRemaining = 0;

    string delimiter = " ";

    string word;

    string sentense;

    int remainder = 0;

    getline(cin, allWords);

    auto start = 0U;
    auto end = allWords.find(delimiter);
    while (end != string::npos)
    {
        word = allWords.substr(start, end - start);

        if (((word.length() + 1) + lineCharacterCount) < maxCharacterCount)
        {
            sentense.append(word);
            sentense.append(" ");
            lineCharacterCount += word.length() + 1;

            start = end + delimiter.length();
            end = allWords.find(delimiter, start);
        }
        else
        {
            word = allWords.substr(start, end - start);

            // Note to myself: Find how many characters are remaining to reach maxCharacterCount minus 1 for the hyphen
            charactersRemaining = (maxCharacterCount - lineCharacterCount) - 1;
            if ((word.length() - charactersRemaining) > 0)
            {
                sentense.append(word.substr(0, charactersRemaining));
                sentense.append("-");
                remainder += 1;
            }

            cout << sentense << endl;
            sentense = "";
            lineCharacterCount = 0;

            if (remainder)
            {
                sentense.append(word.substr(charactersRemaining, string::npos));
                sentense.append(" ");
                lineCharacterCount += word.length() + 1;
                remainder = 0;
            }

            start = end + delimiter.length();
            end = allWords.find(delimiter, start);
        }
    }

    word = allWords.substr(start, end - start);
    sentense.append(word);

    cout << sentense << endl;

    return 0;
}
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
Neil
  • 1
  • 1
    are you using c++ 11 compiler ? – Anson Tan Feb 23 '17 at 03:55
  • i believe so, i am – Neil Feb 23 '17 at 04:25
  • It definitely looks as if you're compiling for the C++03 standard. With g++ add option `-std=c++11`, or `-std=c++14` if the version you have supports it. To get more detailed help please include **the relevant information** such as your compiler and verision, the command you use the build (and any relevant environment variables or other configuration of the compiler), and the diagostic you get quoted verbatim. – Cheers and hth. - Alf Feb 26 '17 at 06:41
  • Removed tag from title and improved formatiting – Barry Michael Doyle Feb 26 '17 at 08:09

1 Answers1

0

set the compiler flags -std=c++11

Sourav Jha
  • 411
  • 2
  • 11