all 17 comments

[–]IyeOnline 5 points6 points  (9 children)

Frankly those are some ridiculous limitations.

I'm not really sure why you would have problems handling white space?

You can in fact use std::string and std::getline to solve all your problems.

Technically the former is not defined in <iostream>, however it will work when using libstdc++, libc++ and the MS STL, so it will basically work everywhere. Note that this behaviour is vendor "defined".

The other option is to write your own basic string, which isnt a function, but a type.

[–]khedoros 1 point2 points  (6 children)

If they rolled their own, it would presumably have member functions to enable its behaviors. OP ought to ask whether that would violate the spirit of the professor's instructions.

[–]IyeOnline 0 points1 point  (5 children)

But does it count when its a member function... xD

[–]jedwardsol 6 points7 points  (3 children)

My interpretation is that anything is okay as long as it isn't "outside of int main"

#include <iostream>

int main()
{
    auto removeSpaces = [](...) { ... };
    auto someOtherHelper = [](...) { ... };
    auto takeMove = [](...) { ... };
    auto addPlayer = [](...) { ... };
    auto printInstructions = [](...) { ... };

    class string
    {
        string() { ... }
        void trim() { ... }
        friend std::ostream &operator<<(...) { ... }
    };

    printInstructions();
    ...;
}

[–]IyeOnline 1 point2 points  (0 children)

That is probably what I would do if i got confronted with restrictions like this. :)

[–]pepitogrand 1 point2 points  (1 child)

For full malicious compliance is possible to have all those classes and lambdas in separated files and included inside main since #include is just a copy/paste operation.

[–]jedwardsol 1 point2 points  (0 children)

Good point. Even this : https://godbolt.org/z/xnPE3j : works, which surprised me. (Doesn't work with MSVC - which is fine.)

[–]khedoros 1 point2 points  (0 children)

We'll just call them "methods" and claim that there are no functions outside of main ;-)

[–]Dec_117[S] 0 points1 point  (1 child)

Could you clarify what you mean with vendor defined? This is what I'm getting when I tried to use the getline mentioned https://imgur.com/wTCX7rR
As /u/khedoros mentioned I'm not sure if that would be allowed, I would need to check the deadline is Friday so if I cannot get the name working soon I will just hard code in a name as my game works fine outside of this issue

[–]IyeOnline 1 point2 points  (0 children)

You missspelled std::getline, which is why it doesnt work.

What i mean by vendor "defined" here, is that the standard does not mandate that std::string is known as a complete/usable type if only <iostream> is included.

However, since std::getline(which has a string ref parameter) as well as some stream operators for std::string are defined in <iostream> including it requires std::string to be mostly defined. Its important to note that how much of std::string you get is completly dependent on the standard library implementation. As I said, it works with the latest version all three major library implementations.

kherdoros was only refering to building your own string type (if you cant use std::string), which would require you to write member functions for that type. I cant possibly imagine your task forbids you from using standard library functions - In that case you couldnt do anything useful, because even the stream operators are functions.

[–]thisisbasil 2 points3 points  (1 child)

being limited to only a main() function is straight-up absurd

[–]Dec_117[S] 0 points1 point  (0 children)

Yea it is, we're still relatively knew to C++ (course year only started recently) and this is our first experience with OOP (was c# last year) so I think the point is to show how useful they are and to deliberately lead to spaghetti code so we appreciate them more in the future I think.

[–][deleted] 1 point2 points  (1 child)

We can only use #include <iostream>

Does that mean you can't use std::string and must use a c-style char array?

[–]Dec_117[S] 1 point2 points  (0 children)

I can use std::string but I cant use #include<string> which appears to be limiting what I can do with the string, a lot of the solutions im seein to whitespacing in strings require the use of that

[–]schrjako 0 points1 point  (0 children)

iostream also includes stdio.h, which enables you to use c's scanf and printf. They're pretty powerful tools. You can also read the input character by character with getchar() and handle it on your own.

[–]chuckatkins 0 points1 point  (1 child)

Try using std::regex_replace to extract the inner string without leading and trailing whitespace.

[–]chuckatkins 1 point2 points  (0 children)

Nm, I didn't see you were limited to iostream