ASCII Art with couts?

My teacher is getting an error with my code somehow using codeblocks on linux and he believes that it's my ascii art/graphics that are causing it. So, what I need to do is switch them over from using raw string literals to couts. The problem is that when I use couts it breaks the art because of escape sequences I believe. Is there some way I can manage to convert the art in my program to couts without ruining them?


https://gist.github.com/Newtochr/3a7b4f7870232ad2d4eefb36e5df16f0
1
2
3
4
5
$ g++ foo.cpp
foo.cpp:85:11: warning: missing terminating " character
  cout << R"(
           ^
// ad nauseam 


vs
 
$ g++ -std=c++11 foo.cpp


Tell your teacher all about C++11.
Thanks for the information about updating his compiler, I can try to go that route and see what he says but what's more likely is that he'll still want me to convert it all to couts.

I'm unsure the implication of the other post though. Do you think I would just like you to give me the code converted? Does it appear I am begging people to do that?

I am attempting to learn here how to do it. To clarify: I do not know how to show my current art using couts in a way that does not ruin it. Any insight would be appreciated.
Copy the ASCII art to a .txt
Then load the txt file and dump to cout.

e.g.
1
2
3
4
5
6
ifstream fin("ascii_art.txt");
string line;
while (getline(fin, line))
{
    cout << line << '\n';
}


My condolences that your professor is using a compiler that is almost a decade old.
Last edited on
The problem is that your teacher is not using a modern compiler and / or not using modern C++ mode when compiling.

If you feel confident with this, tell him he needs to compile with C++17 (or whatever minimum standard you are using, like C++11, which is a no-brainer).

Otherwise, remove that stuff from your code.


As a matter of advice, however, when doing schoolwork, leave that kind of stuff out of your code. Spend time only on the bare-minimum to succeed, and only if you have excessive time left over should you worry about making a really slick presentation.

(Your presentation counts, mind you, so it should be nice to begin with, but anything extra over an assignment’s requirements is not only unnecessary, but uninteresting to almost everyone who will grade your work.)


When submitting assignments, make sure to provide a minimum Makefile that works for GCC and a file named "make.bat" to build your project with MSVC at the command line and/or a MSVC project file that your professor or whoever he is employing to grade your assignment can use.

Yes, it is a little more work on your end, but it can save you a lot of grief later when you get complaints about compiling.


If you find out your teacher is using Borland Turbo C++ (or something equally ancient) you can easily ask him for more time to rewrite the assignment using an ancient compiler system, while the rest of the world is using freely available modern compiler systems, and as the syllabus and introductory class didn’t mention that you would be studying ancient, out-of-date, non-standard C++, you could not have been reasonably prepared to submit such code for grade.

Don’t dare try this if you aren’t very firmly on safe ground.

Hope this helps.
I really like your post here it adds a lot of clarity and I will keep that in mind about future assignments as it seems like solid advice!

The way the class is working is that I carry my first program on into the others so p1 -> p2 -> p3 so I did attempt some art since I had more time after finishing p1. It's probably good to know alternative ways to implement it so it's not all bad in regards to my learning.

I did email my teacher about possibly updating his compiler but my instincts tell me he will likely have me convert anyways which I'm attempting to do quite badly atm. Alas, we will see.
Check the syllabus to see what version of the language is being used. If it says C++11 or higher, then politely point it out to the prof.

If the prof insists, then remove the ASCII art. It's no necessary and you really should spend your efforts on other things.
Chances are, unless your professor is using Turbo C++, he has a compiler sufficiently modern to compile C++11 or better code. Provide him with a Makefile and project files to trigger it properly, and he won’t complain any more.

For GCC-style compiler flags, add -std=c++17 to the command invocation.

For MSVC at the command-line, add /std:c++17 or make sure to select C++17 in the compiler options when you create your project in VS.

Again, I know it is a pain to use multiple compilers, but this is to your net benefit. Anything you ever do online that does not target a specific compiler should be tested with at minimum Clang++9 and MSVC 2019. (And probably the latest GCC as well.)

This is good advice for submitting schoolwork as well, as you really don’t know what compiler(s) your prof/TA/whoever will be using to try to compile your schoolwork, unless the syllabus has specifically said ‘use this compiler because I will be using this compiler’.
So I don't know if you guys will see this but I told my prof about possibly needing to update the compiler and he updated his codeblocks to the latest version. That is not what's required to update the compiler for it, is it? Otherwise it'd work and he said it's still not.

https://i.imgur.com/gspP3j1.png

Your guys advice seems good but also some of it is over my head although with time I can figure it out.

I really haven't been tough much about different compiles or composing files properly to turn in. I generally just attach a .cpp file to an email for him and before I was doing that plus posting the raw code.
It's the gcc version that matters, not the CB version. Are you sure he installed the right thing?

He needs to install codeblocks-20.03mingw-setup.exe, not just codeblocks-20.03-setup.exe (which doesn't include the updated compiler).

http://www.codeblocks.org/downloads/binaries
NOTE: The codeblocks-20.03-setup.exe file includes Code::Blocks with all plugins. The codeblocks-20.03-setup-nonadmin.exe file is provided for convenience to users that do not have administrator rights on their machine(s).

NOTE: The codeblocks-20.03mingw-setup.exe file includes additionally the GCC/G++/GFortran compiler and GDB debugger from MinGW-W64 project (version 8.1.0, 32/64 bit, SEH).

The IDE is not the compiler.

You need to use the C::B build options to tell the compiler which language standard to follow.
https://imgur.com/a/06cLECl
Nah, this is getting too complicated for your professor.

Tell him “thank you”, then load up your version of Code::Blocks, create a project for your code, make sure the compiler options has C++17 checked, (compile for a sanity check), save the project file, then send him the project file.

Problem solved.


[edit]
I just fired up my copy of C::B to check to make sure, and I also managed to re-read salem c’s post, which basically says what I said.

Open C::B, go to Project → Build Options... and in the Compiler Settings tab scroll down a bit to find the “Have (whatever your compiler is) follow the C++17 Language Standards” check box. Click it. Save your project. Give the .cbp file to your professor.

(If you want to make a point, just give him the file by itself. Otherwise, rezip everything so that he can simply unzip, start C::B with the project file, and compile happily.)

Good luck!
Last edited on
Topic archived. No new replies allowed.