#vscode too many errors

68 messages · Page 1 of 1 (latest)

dense hearth
#

(see msgs below)

half moatBOT
#

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.

dense hearth
#
#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;
}```
dense hearth
opaque stag
#

idk, at quick glance I don't see anything explicitly super wrong

#

but

#

min and max are already part of std

dense hearth
#

oh

opaque stag
#

(min > nums.at(i)) ? min = nums.at(i) : min += 0; sus

dense hearth
#

so should i change it to like minvalue or smth

opaque stag
#

probably

#

anyway, comment out all your code

#

then uncomment one line or one function at a time until you find what causes the error

fierce yew
#

https://godbolt.org/z/h1b7a1YKb it's not really a code issue but a tooling issue anyways, your code compiles

#

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

dense hearth
fierce yew
#

I just said why

dense hearth
#

oh i didnt see ur msg below the link thingy

dense hearth
fierce yew
#

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

opaque stag
#

honestly, probably don't use VSCode, just use XCode instead

#

unless you want to learn a bunch of extra stuff 🤷

fierce yew
#

or if you're generating it from a CMake project, you can set that up by setting CMAKE_CXX_STANDARD

dense hearth
opaque stag
#

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

dense hearth
#

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

opaque stag
#

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

opaque stag
#

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

dense hearth
#

do u know of any other good c++ ides

opaque stag
#

in fact it's overall much more difficult

dense hearth
opaque stag
opaque stag
half moatBOT
#
Choosing an IDE/Editor

There is no "best" editor for C/C++. Each has its strengths and weaknesses.

IDEs (Integrated Dev. Envs.)

Specialized editors with built-in tools for building, running, debugging, etc. Heavier, but also much more powerful out of the box.

Code Editors

Less language-specific editors, which are more lightweight. Extra tools for building, running, etc. can be installed via plugins.

More Alternatives

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.

opaque stag
#

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

dense hearth
#

what channel is ur post in

#

is it here in #1013107104678162544

opaque stag
#

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

dense hearth
opaque stag
#

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

dense hearth
#

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

half moatBOT
#

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.