inherit
66746
0
Oct 7, 2012 14:05:38 GMT -8
«The Silver Lining»™
^ Me !!!!
1,338
December 2005
chrisrulez001
|
Post by «The Silver Lining»™ on Jan 4, 2012 13:43:27 GMT -8
Hi
I am having trouble with using vectors in my program i don't know if its the way i'm assigning values to the vectors or what, but i'm really stumped.
Here's my code:
#include <iostream> #include <vector> #include <fstream>
using namespace std;
char add_to_list[33]; vector<char*> list;
int main() { ifstream file("list.txt"); while(!file.eof()) { file >> add_to_list; list.push_back(add_to_list); } file.close();
for(int a = 0; a<list.size(); a++) { cout << list.at(a) << endl; }
cin.get(); }
Contents of list.txt
0 1 2 3 4 5 6 7 8 9 10
All the program is spitting out is the last number in the list, in this case it is the number 10.
Can anyone help please?
|
|
inherit
66746
0
Oct 7, 2012 14:05:38 GMT -8
«The Silver Lining»™
^ Me !!!!
1,338
December 2005
chrisrulez001
|
Post by «The Silver Lining»™ on Jan 5, 2012 8:02:16 GMT -8
Through a bit of trial and error i managed to come up with this code which works a treat:
#include <iostream> #include <vector> #include <fstream> #include <string>
using namespace std;
char add_to_list[33]; vector<string> list;
int main() { string line; ifstream file("list.txt"); while(!file.eof()) { getline(file, line); list.push_back(line); } file.close();
for(int a = 0; a<list.size(); a++) { cout << list.at(a) << endl; }
cin.get(); }
|
|