Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only Detect Text in Quotations (C++)

Tags:

c++

I'm not great at programming and recently started to read tutorials on C++.

I decided I would attempt to make a simple blackjack program. I tried to make a title with "big text" but C++ is preventing me from doing it because it is detecting other things inside the text.

    //Start Screen Begin
cout << " ____  _            _     _            _        ";
cout << "| __ )| | __ _  ___| | __(_) __ _  ___| | __    ";
cout << "|  _ \| |/ _` |/ __| |/ /| |/ _` |/ __| |/ /    ";
cout << "| |_) | | (_| | (__|   < | | (_| | (__|   <     ";
cout << "|____/|_|\__,_|\___|_|\_\/ |\__,_|\___|_|\_\    ";
cout << "                       |__/                     ";
    //Start Screen End

This is what I am trying to display, yet keep getting the following error:

undefined reference to 'WinMain@16'

I am asking if there is a way to tell C++ I only want it to read and display the text, and not use any functions.

like image 592
ICG Avatar asked Jan 25 '14 17:01

ICG


2 Answers

That's a better job for C++11 raw string literals than escaping \ with \\:

#include <iostream>

int main() {
    using namespace std;
    //Start Screen Begin
    cout << R"( ____  _            _     _            _        )" << '\n';
    cout << R"(| __ )| | __ _  ___| | __(_) __ _  ___| | __    )" << '\n';
    cout << R"(|  _ \| |/ _` |/ __| |/ /| |/ _` |/ __| |/ /    )" << '\n';
    cout << R"(| |_) | | (_| | (__|   < | | (_| | (__|   <     )" << '\n';
    cout << R"(|____/|_|\__,_|\___|_|\_\/ |\__,_|\___|_|\_\    )" << '\n';
    cout << R"(                       |__/                     )" << '\n';
    //Start Screen End
}

Check the output here that it works for a decent compiler that support C++11: http://coliru.stacked-crooked.com/a/964b0d2b8bde8b3d

The following would also work:

#include <iostream>

int main() {
    using namespace std;

    //Start Screen Begin
    cout << 
R"(
 ____  _            _     _            _    
| __ )| | __ _  ___| | __(_) __ _  ___| | __
|  _ \| |/ _` |/ __| |/ /| |/ _` |/ __| |/ /
| |_) | | (_| | (__|   < | | (_| | (__|   < 
|____/|_|\__,_|\___|_|\_\/ |\__,_|\___|_|\_\
                       |__/                 
)";
    //Start Screen End
}

http://coliru.stacked-crooked.com/a/b89a0461ab8cdc97

like image 147
pepper_chico Avatar answered Dec 20 '22 05:12

pepper_chico


Your second-to-last text literal has several \ characters in it. That is an escape character, so to use the literal \ character you have to escape it as \\, eg:

cout << "|____/|_|\\__,_|\\___|_|\\_\\/ |\\__,_|\\___|_|\\_\\    ";

It won't look as good in code, but it will look fine when the app is run.

As for the reference error, WinMain() is the entry point for GUI apps, whereas main() is the entry point for console apps, so it sounds like you did not create/configure your project correctly if it is trying to link to WinMain() instead of main().

like image 45
Remy Lebeau Avatar answered Dec 20 '22 05:12

Remy Lebeau