9

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.

4
  • 1
    What development environment are you using? It seems you created a windows project and are not linking the correct libraries. Did you try to create a console application?
    – scraatz
    Commented Jan 25, 2014 at 17:40
  • I'm using Code::Blocks. I'm 99% sure I chose console application when creating my project. I've tried setting up Eclipse Kepler a dozen times but can't get it to work.
    – ICG
    Commented Jan 25, 2014 at 17:47
  • @scraatz This is very unlikely being an issue with the dev environment. Commented Jan 25, 2014 at 17:57
  • 4
    The undefined reference to WinMain indicates that the project setup is Windows GUI application and not console only. You need to know which env he uses to hint him to how to set up the project correctly...
    – scraatz
    Commented Jan 25, 2014 at 18:39

3 Answers 3

71

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

5
  • Better to use std::endl instead of "\n". Commented Jan 25, 2014 at 18:00
  • 31
    @πάνταῥεῖ no, it's not. std::endl purpose is no only adding a new line, but also flushing stdout, and several flushes are not necessary here.
    – oblitum
    Commented Jan 25, 2014 at 18:01
  • I fairly well know it's flushing! Then you should have at least one for the last cout statement ... Commented Jan 25, 2014 at 18:04
  • 11
    @πάνταῥεῖ no need, since it's guaranteed to be flushed before the program ends, and for this sample, it's enough =). No extra hairs are really necessary.
    – oblitum
    Commented Jan 25, 2014 at 18:09
  • 1
    Vimmers also check github.com/vim-jp/cpp-vim/pull/14 for an editor that understand it =). TIP: just add cpp-vim with a plugin manager
    – oblitum
    Commented Jan 28, 2014 at 0:59
13

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().

0
0

You'll need to escape the backslashes, instead of one \ have two \\.

These are used to indicate special characters like "\n" (line-break) appearing within a string literal ("..."). Your Big-Text misses all of those line-breaks BTW.

undefined reference to 'WinMain@16'

Apparently you are trying to compile a GUI project. Check your Code Blocks project type.

Not the answer you're looking for? Browse other questions tagged or ask your own question.