Answer the question
In order to leave comments, you need to log in
How to count characters from a file up to a space in C++?
Tell me how to read characters from a file up to a space in C ++? That is, there is a text file: 456 6546 2345 544 5654 ... etc. Need to count all characters up to each space, how to do it? There is a beginning of the code, it is desirable to build it into it.
void getText () {
bool bRead = false;
long length;
long i, j;
char * text;
ifstream ifs("ggg.txt");
if(!ifs)
cout<<"Error jpen text.txt\n";
else
{
ifs.seekg(0,ios::end);
length = ifs.tellg();
ifs.seekg(0,ios::beg);
if(!(text = new char[length + 1]))
cout<<"Allocation memory error\n";
else
{
ifs.read(text,length);
text[length] = '\0';
}
bRead = !ifs.bad();
ifs.close();
if(bRead)
{
for(i = 0; i < length; i++)
{
if(text[i] == ' ')
<...>
Answer the question
In order to leave comments, you need to log in
wow you did something
void getText () {
std::vector<int> numbers;
int number;
std::ifstream file("file_name.txt")
if (!file) {
std::cout << "error open file file_name.txt" << std::endl;
return;
}
while(!file.eof()) {
file >> number;
numbers.push_back(number);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question