Question on string and std::endl;


why is he giving the example for declaring and initializing a string like this at the beginning of the video?:
std::string Word = “Welcome”;

I havent seen this before.

Isn’t it simply?:
string Word = “Welcome”;

The thing with FString is no issue, I understrood that…

I also want to ask, why does std::cout << std::endl; not work when working with VSCode and Unreal? Or maybe just in this scenario, in the BeginPlay function.

Thank you!

There is no built-in string type in C++. The C++ standard library provides a string class which is is in the std namespace i.e. std::string. Unreal also has an implementation of a string class FString that isn’t in a namespace.

std::cout is mapped to the standard output stream. The in game terminal is not. It’s just text rendered on an in-game object and it was coded by Sam.

1 Like

If you include “using namespace std” after your #includes then you wouldn’t need to use “std::”
Using namespace std is considered bad practice so that’s probably why they avoided teaching it. When you get into much more complex programs where you start building custom headers and libraries you may have more then just std::cout so each time you use it you will have to specify which library you are using cout from.

1 Like

thank you so much.

I have one more basic question on that spot in the game:

what does the Bull Cow Cartridge in the Content Browser represent? It says it’s a C++ class. So is it a class? Or is it simply a code-script?
I have some little experience in workin with Blueprints, so I get my analogies from there. Right now I look at the Cartridge as the Event Graph of an actor, only that I added the EventGraph(Cartridge/C++ Script) manually to my actor(terminal).

But I guess I’m wrong.

I’d also like to know what the U in void UBullCowCartridge::BeginPlay() stands for, and why UBullCartridge is there before ::BeginPlay() ?
Couldnt it simply be BeginPlay() ?

It is a class which you’ve been coding.

To be pedantic it is a component not an actor. You can create an actor component blueprint and then attach that blueprint to any actor.

That the class derives from UObject.

To say that is defining a member function of UBullCowCartridge.

No. That would be defining a non-member function called BeginPlay

class Example
    int Value = 0;
    Example(int N) : Value(N) {}
    int GetValue() const;

int Example::GetValue() const // #1
    return Value;

int GetValue() // #2
    return 20;

int main()
    Example E1(50);
    Example E2(100);
    int V1 = E1.GetValue(); // Calls #1, V1 == 50
    int V2 = E2.GetValue(); // Calls #1, V2 == 100;
    int V3 = GetValue(); // Calls #2 which always returns 20.
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms