0
[SOLVED]In the below code ..I want to give value in the scanf function but it showing error..
6 Answers
+ 3
Hi there, that's because dynamic input is not supported on the SL playground, you have to insert all of your input in one take by separating them with spaces.
+ 3
Line 12:
This loop will trigger an error cause it tries to go beyond the `st[]` array bound (<val> elements). The condition should be `i < val` not `i <= val`.
for( int i = 0; i < val; i++ ) // correct loop condition
Line 15:
`std::string` value cannot be read in using scanf(). `std::string` is not char array (C-string). You need to use `std::cin`
std::cin >> st[ i ];
Line 16:
Undefined variable <s>. Did you mean <st>?
You said you have tried getline() but I don't see it in your code ...
+ 2
Ipang I do getline function is my system (laptop)
other than variable undeclare error....
I want to input the values
+ 1
for (int i = 0; i < val; i++)
{
cout << i << endl;
cin >> st[i];
cout << st[i] << endl;
}
This will do ...
+ 1
Thanks Ipang
0
Maz
2 1
hello
Hello 1
Hello 2
This is how input in SL and yes as u said abt input I do in vs code but it didn't work