#vscode too many errors
68 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <iostream>
#include <vector>
using namespace std;
// prototypes
void print_options();
void print_list(vector<int>);
void add_to_list(int,vector<int>&);
double avg_value(int,vector<int>);
int max_value(int,vector<int>);
int min_value(int,vector<int>);
int main() {
vector<int> nums;
char input;
int num = 0;
int min = 0;
int max = 0;
int total = 0;
do {
print_options();
cin >> input;
switch (input) {
case 'p':
case 'P': print_list(nums); break;
case 'a':
case 'A': add_to_list(num,nums); break;
case 'm':
case 'M': cout << avg_value(total,nums); break;
case 'l':
case 'L': cout << max_value(max,nums); break;
case 's':
case 'S': cout << min_value(min,nums); break;
case 'q':
case 'Q': cout << "Quitting program..."; break;
default: cout << "Invalid input, please try again";
}
} while (input != 'Q' && input != 'q');
cout << endl;
return 0;
}```
void print_options() {
cout << "\nP: Print list\nA: Add item to list\nM: Display avg/mean of items in list" << endl
<< "S: Show smallest value\nL: Show largest value\nQ; Quit" << endl;
}
void print_list(vector <int> nums) {
if (nums.size() != 0) {
cout << "[";
for (int i{}; i < nums.size(); ++i){
cout << nums.at(i) << ", ";
}
cout << "\b\b]";
} else {
cout << "Empty";
}
}
void add_to_list(int num, vector<int> &nums) {
cout << "What would you like to add to the list? ";
cin >> num;
nums.push_back(num);
}
double avg_value(int total, vector <int> nums) {
for (int i{}; i < nums.size(); ++i) {
total += nums.at(i);
}
return total / static_cast<double>(nums.size());
}
int max_value(int max, vector <int> nums) {
for (int i{}; i < nums.size(); ++i) {
if (max < nums.at(i)) {
max = nums.at(i);
}
}
return max;
}
int min_value(int min, vector <int> nums) {
for (int i{}; i < nums.size(); ++i) {
(min > nums.at(i)) ? min = nums.at(i) : min += 0;
}
return min;
}```
these errors dont show up when running in mac terminal
idk, at quick glance I don't see anything explicitly super wrong
but
min and max are already part of std
oh
(min > nums.at(i)) ? min = nums.at(i) : min += 0; 
so should i change it to like minvalue or smth
probably
anyway, comment out all your code
then uncomment one line or one function at a time until you find what causes the error
https://godbolt.org/z/h1b7a1YKb it's not really a code issue but a tooling issue anyways, your code compiles
using namespace std;
// prototypes
void print_options();
void print_list(vector<int>);
void add_to_list(int,vector<int>&);
double avg_value(int,vector<int>);
int max_value(int,vector<int>);
int min_value(int,vector<int>);
int main() {
vector<int> nums;
char input;
int num = 0;
int min = 0;
int max = 0;
int total = 0;
...
so maybe it's something like not compiling with the standard library and then everything else falls apart as a result
maybe this is being compiled as C for whatever reason, and not C++, etc.
ah I know what it is @dense hearth, you're compiling as C++98, which is still the default for Apple Clang
-std=c++20
so then why does vscode show all those errrs
I just said why
oh i didnt see ur msg below the link thingy
how do i make it compile in c++11 or 14 or 17 or 20 im just using the start compilation button
depends on how you're building this, but usually you should have a build.json or something where you can configure everything, such as the C++ standard
honestly, probably don't use VSCode, just use XCode instead
unless you want to learn a bunch of extra stuff 🤷
or if you're generating it from a CMake project, you can set that up by setting CMAKE_CXX_STANDARD
i tried xcode but it wouldnt let me compile/run a c++ file unless i make a new one it wont let me open a c++ file and run it it just opens as txt
i dont think i use cmake
I mean, I somewhat doubt that's entirely true, but why is that a problem? so just make a new project and a new file and copy/paste your old code
it doesn't seem like you have thousands or millions of files, really just one so far I think
and not a very large one at that
anyway, frankly you'll probably struggle if you try to use VSCode. while XCode requires some learning too, you'll probably have far less pain with XCode than anything else
for reasons detailed here https://cpp-doge.github.io/limbo/use-an-ide/#motivations
but id rather just be able to open it rather than just creating a new file i would have to delete the old one duplicates tend to bother me
also what abt codelite
hey, if you prefer to learn and study what you need to be successful, go ahead
but it won't be easy, and I detail this rather verbosely and explicitly in my post
I still feel this is a non-sequitur
if you use XCode you'll just be using XCode
like you may have to copy/paste 50 lines this once
any and all future projects should be no more or less work in general than creating a new file etc with any other tool
you'd have to create a new file and build and config for vscode pretty much every time anyway, it's not easier
do u know of any other good c++ ides
in fact it's overall much more difficult
what is
for you as a beginner on mac? no not really, XCode is kind of it
using vscode
There is no "best" editor for C/C++. Each has its strengths and weaknesses.
Specialized editors with built-in tools for building, running, debugging, etc. Heavier, but also much more powerful out of the box.
- Visual Studio (free, Windows)
- Xcode (free, macOS)
- Qt Creator (free, any OS)
- CLion (free for students, open-source, any OS)
- repl.it (free for open-source, in-browser)
Less language-specific editors, which are more lightweight. Extra tools for building, running, etc. can be installed via plugins.
- Visual Studio Code (free, any OS)
- Sublime Text (free, any OS)
- Vim, Emacs, Micro: (free, terminal)
All the above work for many languages, not just C/C++.
You can use practically any text editor, even Notepad to write your code. C and C++ can be compiled and run directly from the command line. However, this setup is difficult to use and to make as powerful as an IDE.
anyway, if you really want to go down the hard road, my post covers just about everything you could need or want to know about this stuff
my claim is that anything other than XCode on mac is "the hard road", ymmv
my blog post ☝️
The following is a list of notable text editors.
The following tables list notable software packages that are nominal IDEs; standalone tools such as source code editors and GUI builders are not included. These IDEs are listed in alphabetical order of the supported language.
there are many to choose from, but the easiest, least painful path to coding instead of worrying about all this is to just use XCode, anyway, good luck
i didnt see anything abt mac or xcode there just windows and vs and vscode and mingw
that's an internal link
read from the top
it's not really an article that's OS specific, this general situation applies to tons of beginners in here
it's really common that beginners try to use VSCode, and this causes pain, and my general recommendation is to use the official IDE for your OS which is Visual Studio on Windows, XCode on Mac
so, the general premise applies across the board, all the reasons to use Visual Studio on Windows are basically the same reasons to use XCode on Mac
wait i got vscode to work i had to make a tasks json file i had to add -std=c++17 in the args section
This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.