-1
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S = 0; 
    int T,R;
    
    cin >> S >> R;
    
    for(int i = 0; i < T; i++)
    {
        for(int k = 0; k < S.length(); k++)
        {
            for(int j = 0; j < R; j++)
            {
                cout << S[k];
            }
        }
        cout << endl;
    }
    
    return 0;
}

The error pool statement is:

terminate called after throwing an instance of 'std::logic_error'
   what(): basic_string::_S_construct null not valid
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 4
    Funny that you would try to initialize a `std::string` to 0 when it isn't necessary but not initialize the other variables where it is good practice. Since `T` is uninitialized and never assigned it's probably not the best thing to use as your loop limit. – Retired Ninja Nov 02 '21 at 12:40

2 Answers2

5

string S = 0; is interpreted as std::string S{nullptr}; which is forbidden.

Just write string S; instead.

m88
  • 1,968
  • 6
  • 14
4

After you fix the hard error of string S = 0;, you also have undefined behaviour, as you use T without initialising it.

Also using namespace std; pulls in far too many names, you shouldn't do it.

#include <iostream>
#include <string>

int main()
{
    std::string S; 
    int R;
    
    std::cin >> S >> R;
    
    for(int i = 0, T = 1/*???*/; i < T; i++)
    {
        for(char c : S)
        {
            for(int j = 0; j < R; j++)
            {
                std::cout << c;
            }
        }
        std::cout << std::endl;
    }
    
    return 0;
}
Fred Larson
  • 60,987
  • 18
  • 112
  • 174
Caleth
  • 52,200
  • 2
  • 44
  • 75