consteval
#include <bits/stdc++.h> int main() { std::cout<<"hello world"; return 0; }
<bits/stdc++.h> is an internal header specific to GCC. Since you only use std::cout in your code, you should just #include <iostream> instead
consteval
nice
Rohit
Which programming should I choose if I want to earn heavy
Rose
Which programming should I choose if I want to earn heavy
Offtopic discussions should be done in the C/C++ Offtopic group. Please take your discussion/questions there.
Adrian
/start@MissRose_bot
Rose
/start@MissRose_bot
Heya :) PM me if you have any questions on how to use me!
Adrian
Which library should I use to display something with encoding utf-8 that allows me to use special characters? #include <?.h>
Rose
Reported Manu [552765840] to admins.​​​​​​​​​​
Chat Boss
Igor Kozelskiy sent a code, it has been re-uploaded as a quote I have a pretty big file of .md type of 139761 lines. My function readlines perfectly reads file of smaller sizes, but when reading this one it finds 139779 lines. c #include "strarray.h" #include <stdio.h> #include <stdlib.h> #include <string.h> int readlines(FILE *file, StrArray *lines) { char buffer[BUFFER_SIZE]; memset(buffer, 0, sizeof buffer); while (fgets(buffer, sizeof(buffer), file)) { buffer[strcspn(buffer, "\n")] = 0; if ((str_array_append(lines, buffer)) < 0) { str_array_terminate(lines); return -1; } } return lines->size; } int str_array_append(StrArray *array, const char *new_str) { if (!array || !new_str) { fprintf(stderr, "add_str: NULL pointer detected\n"); return -1; } char **strs_upd = (char **)realloc(array->array, sizeof(char *) * (array->size + 1)); if (!strs_upd) { perror("realloc failed"); return -1; } strs_upd[array->size] = malloc(strlen(new_str) + 1); if (!strs_upd[array->size]) { perror("malloc failed"); return -1; } strcpy(strs_upd[array->size], new_str); array->array = strs_upd; array->size++; return array->size; } void str_array_terminate(StrArray *array) { if (!array || !array->array) return; for (size_t i = 0; i < array->size; i++) if (array->array[i]) free(array->array[i]); free(array->array); array->array = NULL; array->size = 0; }
Igor
No idea why it reads more lines than there're actually in file
Chat Boss
What's your strarray.h
Igor Kozelskiy sent a code, it has been re-uploaded as a quote Function declarations #ifndef STRARR_H #define STRARR_H #include <stdlib.h> #include <stdio.h> #define BUFFER_SIZE 2048 typedef struct _str_array_ { char **array; int size; } StrArray; int readlines(FILE *file, StrArray *array); int str_array_append(StrArray *array, const char *new_string); int str_array_insert(StrArray *array, size_t position, const char *new_string); int str_array_drop(StrArray *array, size_t position); int str_array_drop_range(StrArray *array, size_t start, size_t end); int str_array_replace(StrArray *array, size_t index, char *replacement); int str_array_replace_range(StrArray *array, size_t start, size_t end, StrArray *rrange); void str_array_terminate(StrArray *array); #endif // !STRARR_H
Never Spam Bot
Igor Kozelskiy is now approved by the group admin and can send messages without any restrictions Function declarations #ifndef STRARR_H #define STRARR_H #include <stdlib.h> #include <stdio.h> #define BUFFER_SIZE 2048 typedef struct _str_array_ { char **array; int size; } StrArray; int readlines(FILE *file, StrArray *array); int str_array_append(StrArray *array, const char *new_string); int str_array_insert(StrArray *array, size_t position, const char *new_string); int str_array_drop(StrArray *array, size_t position); int str_array_drop_range(StrArray *array, size_t start, size_t end); int str_array_replace(StrArray *array, size_t index, char *replacement); int str_array_replace_range(StrArray *array, size_t start, size_t end, StrArray *rrange); void str_array_terminate(StrArray *array); #endif // !STRARR_H See spam? Quote the spam message in the group and reply with /spam
Igor
Well, I found the mistake.... Buffer was too small (2k chars was not enough) to handle lines from the file
Nikhil
Any body need gaming code for c++
Ludovic 'Archivist'
elsahou
no
Ludovic 'Archivist'
/warn English only
Rose
User 😊 has 1/2 warnings; be careful! Reason: English only
Ludovic 'Archivist'
/warn English only
Rose
User Madhav has 1/2 warnings; be careful! Reason: English only
Rose
User Nikhil has 1/2 warnings; be careful! Reason: spam/ad
Nikhil
What
Nikhil
Please remove me
klimi
What
Read the rules
klimi
Please remove me
Remove yourself
Nikhil
No
Nikhil
I can't
Nikhil
.
Nikhil
.
Rahul
Does anybody can do the coding for my website?
klimi
Does anybody can do the coding for my website?
This group is not for advertising jobs
Rose
Does anybody can do the coding for my website?
Click on the button to see the chat rules!
Psych
anyyy senior c programmerssss hereee????
Aze
can the result of an RNG system ever be the same
Aze
like could the result of a crash game be replicated such that it so similar to the results of the game itself
Aze
is there any possibility
Suka
any suggestions pls?
virtualbox perhaps?
Don
yeah
Sam
Yeah
klimi
/warn repeated ad
Rose
User Rahul has 1/2 warnings; be careful! Reason: repeated ad
Shruti
Indian?
V22001
klimi
Read the rules
Unknown Bot
Read the rules
Why it's happening
Unknown Bot
Emojis are not allowed? :(
klimi
Emojis are not allowed? :(
They are not forbidden. But I don't know how you can use emoji on topic
Rose
User Malikzada Ahsan has 1/2 warnings; be careful! Reason: homework
Lemuel
Hi am new
Yurri
Hey all
klimi
Hi am new
Then please read the rules
Yurri
Is there any idea how to convert our website into a legal application?
GPU Governor
Hi am new
For messages like this, you should consider joining the C++ offtopic group
Rose
Hi am new
Offtopic discussions should be done in the C/C++ Offtopic group. Please take your discussion/questions there.
GPU Governor
Is there any idea how to convert our website into a legal application?
Yeah, that's what tools like electron and tauri is for
GPU Governor
You will write the application with html, css, js. Then bundle it as a web view (web container)
GPU Governor
And since this is a c++ group, i will recommend you use Qt webview
Ludovic 'Archivist'
And since this is a c++ group, i will recommend you use Qt webview
I never used it, is it good? I generally make my web tools using drogon and htmx
GPU Governor
I never used it, is it good? I generally make my web tools using drogon and htmx
On a scale of 10 i will give it a 6.5, i only use qt webview if i want my code base to be in C++ otherwise they are better alternatives like the ones you are already using
Sharan
Any one want projects ping me
Don
Any one want projects ping me
Hello. I want a project which can make my skill high
Kayathri
Hello I need help in my c++ assignment urgent
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote #include "include/Battlefield.h" #include "include/BattleShip.h" #include "include/Cruiser.h" #include "include/Destroyer.h" #include "include/Frigate.h" #include "include/Corvette.h" #include "include/Amphibious.h" #include "include/Supership.h" #include "include/Game_Setup.h" #include "include/MovingShip.h" #include "include/RamShip.h" #include "include/SeeingShip.h" #include "include/Ship.h" #include "include/ShootingShip.h" #include "include/Supership.h" #include <iostream> #include <fstream> // For file operations using namespace std; int main() { ofstream outFile("output.txt"); // Create output file streambuf* coutbuf = cout.rdbuf(); // Save old buf cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt Battlefield battlefield(15, 15); cout << "Created battlefield" << std::endl; battlefield.printBattlefield(); Battleship BattleShip("BattleShip", 1, 1, battlefield, 1); Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2); Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3); Frigate Frigate("Frigate", 5, 11, battlefield, 4); Corvette Corvette("Corvette", 9, 3, battlefield, 5); Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6); Supership Supership("Supership", 5, 6, battlefield, 8); battlefield.printBattlefield(); for (int step = 0; step < 22; step++) // step { cout << "Step " << step << "\n" << endl; BattleShip.takeTurn(); battlefield.printBattlefield(); Cruiser.takeTurn(); battlefield.printBattlefield(); Destroyer.takeTurn(); battlefield.printBattlefield(); Frigate.takeTurn(); battlefield.printBattlefield(); Corvette.takeTurn(); battlefield.printBattlefield(); Amphibious.takeTurn(); battlefield.printBattlefield(); Supership.takeTurn(); battlefield.printBattlefield(); } cout << "End of simulation" << endl; cout.rdbuf(coutbuf); // Reset to standard output again outFile.close(); // Close output file return 0; } C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)' anyone can help my code has no error but when I run it shows this output I don't know why its not running
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote #include "include/Battlefield.h" #include "include/BattleShip.h" #include "include/Cruiser.h" #include "include/Destroyer.h" #include "include/Frigate.h" #include "include/Corvette.h" #include "include/Amphibious.h" #include "include/Supership.h" #include "include/Game_Setup.h" #include "include/MovingShip.h" #include "include/RamShip.h" #include "include/SeeingShip.h" #include "include/Ship.h" #include "include/ShootingShip.h" #include "include/Supership.h" #include <iostream> #include <fstream> // For file operations using namespace std; int main() { ofstream outFile("output.txt"); // Create output file streambuf* coutbuf = cout.rdbuf(); // Save old buf cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt Battlefield battlefield(15, 15); cout << "Created battlefield" << std::endl; battlefield.printBattlefield(); Battleship BattleShip("BattleShip", 1, 1, battlefield, 1); Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2); Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3); Frigate Frigate("Frigate", 5, 11, battlefield, 4); Corvette Corvette("Corvette", 9, 3, battlefield, 5); Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6); Supership Supership("Supership", 5, 6, battlefield, 8); battlefield.printBattlefield(); for (int step = 0; step < 22; step++) // step { cout << "Step " << step << "\n" << endl; BattleShip.takeTurn(); battlefield.printBattlefield(); Cruiser.takeTurn(); battlefield.printBattlefield(); Destroyer.takeTurn(); battlefield.printBattlefield(); Frigate.takeTurn(); battlefield.printBattlefield(); Corvette.takeTurn(); battlefield.printBattlefield(); Amphibious.takeTurn(); battlefield.printBattlefield(); Supership.takeTurn(); battlefield.printBattlefield(); } cout << "End of simulation" << endl; cout.rdbuf(coutbuf); // Reset to standard output again outFile.close(); // Close output file return 0; } C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote "#include "include/Battlefield.h"" #include "include/BattleShip.h" #include "include/Cruiser.h" #include "include/Destroyer.h" #include "include/Frigate.h" #include "include/Corvette.h" #include "include/Amphibious.h" #include "include/Supership.h" #include "include/Game_Setup.h" #include "include/MovingShip.h" #include "include/RamShip.h" #include "include/SeeingShip.h" #include "include/Ship.h" #include "include/ShootingShip.h" #include "include/Supership.h" #include <iostream> #include <fstream> // For file operations using namespace std; int main() { ofstream outFile("output.txt"); // Create output file streambuf* coutbuf = cout.rdbuf(); // Save old buf cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt Battlefield battlefield(15, 15); cout << "Created battlefield" << std::endl; battlefield.printBattlefield(); Battleship BattleShip("BattleShip", 1, 1, battlefield, 1); Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2); Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3); Frigate Frigate("Frigate", 5, 11, battlefield, 4); Corvette Corvette("Corvette", 9, 3, battlefield, 5); Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6); Supership Supership("Supership", 5, 6, battlefield, 8); battlefield.printBattlefield(); for (int step = 0; step < 22; step++) // step { cout << "Step " << step << "\n" << endl; BattleShip.takeTurn(); battlefield.printBattlefield(); Cruiser.takeTurn(); battlefield.printBattlefield(); Destroyer.takeTurn(); battlefield.printBattlefield(); Frigate.takeTurn(); battlefield.printBattlefield(); Corvette.takeTurn(); battlefield.printBattlefield(); Amphibious.takeTurn(); battlefield.printBattlefield(); Supership.takeTurn(); battlefield.printBattlefield(); } cout << "End of simulation" << endl; cout.rdbuf(coutbuf); // Reset to standard output again outFile.close(); // Close output file return 0; } C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
Never Spam Bot
Kayathri Rayan sent multiple messages that looks like a spam. Why was my message deleted? Spam deleted in this group: 3181
Suka
Kayathri Rayan sent a code, it has been re-uploaded as a quote "#include "include/Battlefield.h"" #include "include/BattleShip.h" #include "include/Cruiser.h" #include "include/Destroyer.h" #include "include/Frigate.h" #include "include/Corvette.h" #include "include/Amphibious.h" #include "include/Supership.h" #include "include/Game_Setup.h" #include "include/MovingShip.h" #include "include/RamShip.h" #include "include/SeeingShip.h" #include "include/Ship.h" #include "include/ShootingShip.h" #include "include/Supership.h" #include <iostream> #include <fstream> // For file operations using namespace std; int main() { ofstream outFile("output.txt"); // Create output file streambuf* coutbuf = cout.rdbuf(); // Save old buf cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt Battlefield battlefield(15, 15); cout << "Created battlefield" << std::endl; battlefield.printBattlefield(); Battleship BattleShip("BattleShip", 1, 1, battlefield, 1); Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2); Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3); Frigate Frigate("Frigate", 5, 11, battlefield, 4); Corvette Corvette("Corvette", 9, 3, battlefield, 5); Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6); Supership Supership("Supership", 5, 6, battlefield, 8); battlefield.printBattlefield(); for (int step = 0; step < 22; step++) // step { cout << "Step " << step << "\n" << endl; BattleShip.takeTurn(); battlefield.printBattlefield(); Cruiser.takeTurn(); battlefield.printBattlefield(); Destroyer.takeTurn(); battlefield.printBattlefield(); Frigate.takeTurn(); battlefield.printBattlefield(); Corvette.takeTurn(); battlefield.printBattlefield(); Amphibious.takeTurn(); battlefield.printBattlefield(); Supership.takeTurn(); battlefield.printBattlefield(); } cout << "End of simulation" << endl; cout.rdbuf(coutbuf); // Reset to standard output again outFile.close(); // Close output file return 0; } C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
see your error msg, make sure that your library .h have implementation for used function, it can be in seperate .c/cpp file or seperate binary object/library. and your compiler need to pointed to those file.
Anshul
Do we have any such group for python(and other programming languages) as well?