1

I want to be able to set the console size to be exacly the same no matter what device it runs on, so far I have used

static const int nScreenWidth = 80;
static const int nScreenHeight = 30;
int main()
{
    system("MODE CON COLS=80 LINES=30");
}

But since I`m storing the width and height in variables it needs to be changed manually and that is not cool. I have tried

system("MODE CON COLS=" + std::to_string(nScreenWidth).c_str() + " LINES=30");

but I get expression must have integral or unscoped enum type.

All of the functions from

#include <windows.h>

set the console size in pixels but I need it to be in characters.

SzymonO
  • 432
  • 3
  • 15
  • `"MODE CON COLS=" + std::to_string(nScreenWidth).c_str() + " LINES=30"` do all that with the `std::string` first. Here your problem is you are trying to append 3 c-strings – drescherjm May 13 '20 at 16:43
  • Works wonderful, out of curiosity why can`t you add 3 c-strings together? – SzymonO May 13 '20 at 16:58
  • They are dumb and don't support operator+() remember these are from `c`. Related: [https://stackoverflow.com/questions/15319859/how-to-concatenate-two-strings-in-c](https://stackoverflow.com/questions/15319859/how-to-concatenate-two-strings-in-c) – drescherjm May 13 '20 at 16:59
  • C-strings are just char arrays or pointers to the first element of char arrays. There's no `+` operator overloaded for char arrays or char pointers. – eesiraed May 13 '20 at 18:03

1 Answers1

0

See if this helps:

std::string str = "MODE CON COLS=" + std::to_string(nScreenWidth) + " LINES=30";

system(str.c_str());
user9559196
  • 157
  • 6