#visual studio 2022 bug or im stupid

33 messages · Page 1 of 1 (latest)

azure reef
#
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;

bool isPalindrome(const char* input, int size) {
    int i = 0, j = size - 1;

    while (i < j) {
        while (!isalnum(input[i]) && i < j) {
            i++;
        }

        while (!isalnum(input[j]) && i < j) {
            j--;
        }

        if (tolower(input[i]) != tolower(input[j])) {
            return false;
        }

        i++;
        j--;
    }

    return true;
}

int main() {
    string str;
    cout << "Enter a string: ";
    getline(cin, str);

    int size = str.length();
    const char* input = str.c_str();

    bool result = isPalindrome(input, size);

    if (result) {
        cout << "\nYes, '" << str << "' is a palindrome" << endl;
    } else {
        cout << "\nNo, '" << str << "' is not a palindrome." << endl;
    }

    return 0;
}```


this will run on like online c++ compilers but won't run on visual studio 2022
cedar voidBOT
#

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.

uneven schooner
#

Does it at least compile?

azure reef
#

it compiles on but https://www.onlinegdb.com/ but it wont on vs studio 2022

runic horizon
#

What is the error message?

uneven schooner
#

What is the error message?

runic horizon
#

std::string is in the header <string>.

azure reef
uneven schooner
#

iirc iostream including string is standard

runic horizon
uneven schooner
#

!cppref getline

cedar voidBOT
#
template<
    class CharT,
    class Traits,
    class Allocator>
std::basic_istream<CharT, Traits>& getline(
    std::basic_istream<CharT, Traits>& input,
    std::basic_string<CharT, Traits, Allocator>&
        str,
    CharT delim);
// ... and 3 more
Defined in
runic horizon
#

So yeah @azure reef you are just not aware enough.

uneven schooner
#

Try including <string>
getline is part of that library

azure reef
#

bro yall r jesus thank you

azure reef
cedar voidBOT
#

@azure reef Has your question been resolved? If so, run !solved :)

clever shell
#

<iostream> has 0 requirments to include <string> or all of it

uneven schooner
runic horizon
#

And that someone was wrong.

uneven schooner
#

Yes I got that

clever shell
#

afaik there are 0 dependencies in the STL

#

I thought that pretty much every include was stand alone

#

could be wrong on that though :P

uneven schooner
#

Actually looking into iostream, there are standard dependencies. One moment

runic horizon
#

std::getline relies on std::basic_istream.

clever shell
#

anyhow might be a bit wrong, but I thought all of them where "stand" alone in some sense

uneven schooner
runic horizon
#

(Why does Samsung save screenshots as JPG...)

uneven schooner
#

Saves space?

runic horizon
#

Doesn't save as much space.

uneven schooner
#

The amount of time I care for the losslessness of png is few and far between