I am new to C++ language and I was looking for clear answer to my problem but with no result. What I am trying to do is get substr
value of the string which is single line in text file. When I run compilation like this I receive first twelve letters of the sentence and I don't have problem with that:
a[count] = sentence.substr(0,12);
but when I am trying to change pos
from 0
to any other value for example:
a[count] = sentence.substr(1,12);
I receive error:
terminate called after throwing an instance of std::out_of_range what(): basic_string::substr: _pos (which is 1) this -> size() (which is 0)
I checked it with YT and online guides and no one had problem with substr
.
Any ideas?
EDIT: Sorry for confusion cause. This is a part of the code:
string sentence;
string a[10000];
string next_line[10000];
main()
{
int count = 1;
fstream file;
file.open("converted.txt",ios::in);
while(!file.eof())
{
getline(file, line);
next_line[count] = line;
sentence = next_line[count];
a[count] = sentence.substr(1,12);
count++;
}
}