oh, i forgot to add that all the data in the second file is suppose to be separate, not in one line then the rest in one line (which would be the integers)
So you're basically asking how to convert a String to an integer??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <sstream>
usingnamespace std;
int main()
{
usingnamespace std;
string s = "1234";
stringstream ss(s); // Could of course also have done ss("1234") directly.
int i;
if ((ss >> i).fail()) {
//error
}
cout<<i<<endl;
return 0;
}
You could also use boost lexical cast which would be the cleanest solution IMHO...
no... i guess i'll be more specific on the type of program i'm trying to create
see there's a file with the seven days of the week (this is the first line...comma delimited)
then there are seven lines with integers also comma delimited because it's more than one set of data (each line will go to one of the days of the week)
what i want to know is how do i input both text and integers from the data so that I can separate each line into one of the days of the week
this is what the text file looks like:
You can work with splitting the strings....
Read every line on it's own...
Then on the first line (3422 2352 ...) you split the strings by ' ' (whitespace)
Splitting a string is pretty straight forward... You can work with find() and substr(int from, int to)