#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{


    cout <<"enter the problemset and number""\n";
    //problems represents name and numbers
    string problems;
    string problem_name_and_numbers=problems;
    string numbers;
    char quote;
    int total_length=problems.length();
    //gather name
    if(cin.peek()=='"' || cin.peek() == '\'')
    {
        cin >>quote;
        getline(cin,problems,quote);
        int problemslength=(problems.length()+1);
        int difference=total_length-problemlength;
        numbers=problem_name_and_numbers.substr(problemlength,difference);
    }
    else
    {
        getline(cin,problems);
        int problemslength=(problems.length()+1);
        int difference=total_length-problemlength;
        numbers=problem_name_and_numbers.substr(problemlength,difference);
    }

    //gather problem numbers

    return 0;
}

Dani AI

Generated

A quick note for future readers: the compile-time complaint in this thread was resolved by the original poster (), but the cause seen here is very common and worth documenting.

Common causes and a short checklist

  • Typos and inconsistent names are the number-one cause. C++ identifiers are case-sensitive and must match exactly where declared and used.
  • Scope matters: a name declared inside a pair of braces is not visible outside them. Declare values in the right block or move the declaration higher.
  • Make sure each variable is declared before it’s used. Built-in types left uninitialized cause UB; standard library types like std::string default to empty but still must be declared first.
  • Use the compiler’s error line numbers to find the spot, and enable warnings (for gcc/clang use -Wall -Wextra) to catch other problems early.
  • Include the correct headers when using library types or functions (for strings see the <string> header).

Minimal example of the right idea (different names than the original post):

#include <iostream>
#include <string>

int main() {
    std::string title;
    std::getline(std::cin, title);

    std::size_t title_len = title.length(); // declared and used consistently
    if (title_len > 0) {
        std::string tail = title.substr(1); // safe use after checks
    }
    std::cout << "length=" << title_len << '\n';
    return 0;
}

References and final tips: read about C++ scope rules and the string length/size member for exact behavior: scope rules, , and <string> header. Use an editor that highlights unknown symbols to catch misspellings quickly.

it doesn't like problems.length

problemlength wasn't declared in this scope

Are you asking a question or answering your own question ???

i got it to work. So i don't need help anymore.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.