r/AskProgramming • u/BornViolinist3801 • Aug 01 '26
why doesnt my С++ code work?
okay, i wanna make a print() function in C++, this is just printf() with prefix, so can yall help me?
error:
(-Wwritable-strings) ISO C++11 does not allow conversion from string literal to 'char *'my code:
#pragma once
#ifndef TEQUILA_STDIO
#define TEQUILA_STDIO
#include <stdio.h>
namespace std {
char* prefix;
void set_prefix(char* pref) {
prefix = ("["pref"]: ");
}
#define print(format, ...) printf("%s" format "\n", prefix ## __VA_ARGS__)
}
#endifhelp me pls
0
Upvotes
View all comments
Show parent comment
1
u/BoopyDog Aug 01 '26
I started writing seriously in C++ and never spent much time writing with C so I tend to use references and stay away from actual p*=&a style programming. As far as I understand it, a reference is implemented as a pointer which is always automatically dereferenced. Of course, you're correct.