String array into double array

Hey so couldnt find a way to read in a text file to a double array. So I read it in using getline, into a string array. Now I want to convert the string array into a double array, or read in a txt data file with this syntax:

1
2
3
4
5
...

into a double array.Thanks for taking a look!
1
2
#include <stdlib.h>
double strtod(const char *nptr, char **endptr);

you could use this function. just use the address of the sting (only one number) as first arument. you may set the second argument NULL but if you pass a pointer to a string, it will store all invalid characters there.
Thanks for responding. I have a std::string not a Cstring so I dont think this will work. Thanks though.
1
2
string mystring = "6.0";
double value = strtod(mystring.c_str());
Whats wrong with this for reading the doubles?
1
2
3
ifstream in("numbers.txt");
double d;
in >> d;


Please post your code as to why reading doubles isn't working.
@lowestone
this does not check, wether the strimg it reads is actuly a number. a wrong input could crash the whole program. thats why you should read the string into an array or string, check wether its a valid number and then convert it into doubles.
Use stringstream?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	std::fstream iFile;
	iFile.open( "myTextFile.txt" );

	std::string input = "";	

	if( iFile.is_open() )
	{
		while( iFile.good() )
		{
			std::getline( iFile, input, '\n' );

			std::stringstream ss( input );
			double myDouble = 0;

			if( ss >> myDouble )
				std::cout << myDouble << '\n';
			else
				std::cout << "Invalid double...\n";
		}
		
		iFile.close();
	}
	else
		std::cout << "Error opening file...\n";


Input from file:
1
3.03
g
5
93
.
7


Output:
1
3.03
Invalid double...
5
93
Invalid double...
7
Topic archived. No new replies allowed.