Hello
I have a problem with reading the coordinates of points which are extracted from (..txt ) file.I have read the file with ifstream but I don't know how to use the information then. Thanks in advance
the point are in File as followed :
u:1.2000 v:4.5400
u:2.5450 v:6.4500
snipermann
0
Newbie Poster
Recommended Answers
Jump to PostRead a line in the file into a std::string with getline() and then parse that string with a stringstream.
I'm not sure it's the most efficient way to do it, but to start, break it in half on the space, then read the halves up until ':' and throw …
Jump to PostAre your numbers guaranteed to be a fixed number of digits? If not, you'll have to do the splitting like I was saying.
For the way you have it:
point pt; stringstream ss(xcor); //set up a stringstream with the first string ss >> pt.x; //extract the …
Jump to PostYou need to use the .c_str() method of your strings to get their C-string representation:
point pt; pt.x = atof(xcor.c_str()); //etc.
Jump to PostNo, apologies. It's either one or the other. Presumably you'll want an array of points, so you can incorporate the code into your while loop and increment an index to keep track of where you are in the points array.
Jump to PostLine 28 should be eliminated.
You will probably want to declare an array of points (or a vector if you don't know how many you will have) somewhere around line 20 or wherever it makes sense.
In this example, as long as you have declared a point pt, …
All 21 Replies
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
snipermann
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
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.