Hi everybody,

I really need that code,

I have a text file

32 4
12 13 4 12
0 0 0 0 0 3 2 3 4

and I want to convert it vector or array

like A[2]={32,4} B[4]={12,13,4,12} C[9]={0,0,0,0,0,3,2,3,4}

The size of the vector or array can be changed everytime.

:icon_rolleyes:

>I really need that code
Then write it. That's what I do when I really need code for something.

>I have a text file
>and I want to convert it vector or array

I'm sure you've used cin's >> operator to read integers from standard input. What you did was read a stream of text and convert it to int, though most of that work happened under the hood. You can do the same thing with your file:

#include <fstream>

int main()
{
    std::ifstream in("myfile");
    int x;

    if (in && in>> x)
        std::cout<< x <<" squared is "<< x * x <<'\n';
}
commented: sometimes i think you're almost human.(sometimes) +1

If you are having problem with converting text '1' into integer 1 then look at the ASCII table. There you see the decimal value of character '1' is 49.

There if you read '1' into an integer variable you are holding 49. If you just decrease that by 48 you get 1. It goes same for 2 and 3 and .. too.

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.