If I have in a text file a word followed by numbers, how would I read only the numbers?
Ex:
Add 5645635654653463546.
wleemitch
0
Newbie Poster
Recommended Answers
Jump to Postcreate an ifstream object and use its >> operator to skip the first word and read the second.
ifstream in("file"); string word; in >> word; // read "Add" in >> word; // read the digits
Jump to Postthe >> operator first skips all leading space then reads all the characters up to the next space. So if the file contains " Add 5645635654653463546" the >> operator reads Add into the string word. Then the next line the >> operator erases what it in word and reads the …
Jump to PostI've made a program similar to yours. It compiles and runs but the console is empty. Are we suppose to use ofstream?
ofstream will produce output to a file, not the console. cout is from iostream and will display to the console. That's what Ancient Dragon is doing here in …
Jump to PostHowever he did forget one important thing at the end of his program. :)
return 0;
Nope, I didn't forget it. Its optional. return 0 is the default if nothing is specified. That was a fairly recent addition to the c++ standards so some older compilers may require …
All 15 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
wleemitch
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
wleemitch
0
Newbie Poster
VernonDozier
2,218
Posting Expert
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
VernonDozier
commented:
You are correct.
+2
VernonDozier
2,218
Posting Expert
Featured Poster
wleemitch
0
Newbie Poster
wleemitch
0
Newbie Poster
VernonDozier
2,218
Posting Expert
Featured Poster
wleemitch
0
Newbie Poster
VernonDozier
2,218
Posting Expert
Featured Poster
wleemitch
0
Newbie Poster
VernonDozier
2,218
Posting Expert
Featured Poster
wleemitch
0
Newbie 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.