... still. does not work. Here is the errors:
vector test\opening files with vector.cpp||In function 'int opnfile()':|
vector test\opening files with vector.cpp|45|error: request for member 'push_back' in 'lines', which is of non-class type 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >()'|
vector test\opening files with vector.cpp|52|warning: pointer to a function used in arithmetic|
vector test\opening files with vector.cpp|52|error: invalid conversion from 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > (*)()' to 'char'|
vector test\opening files with vector.cpp|52|error: initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'|
||=== Build finished: 3 errors, 1 warnings ===|
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;
int opnfile()
{
system("CLS");
Sleep(10);
while(_kbhit()) _getch(); // clears the getch() stream
vector<string> lines();
string txt;
int x, lin;
x = 0;
ofstream gro; // opens and writes data top a file for testing
gro.open("groceries.txt", ios::out);
if (gro.is_open())
{
gro<< " This is the grocery list"<< endl;
gro<< ""<< endl;
gro<< " 1- tomatoes and starch"<< endl;
gro<< " 2- potatoes and beans x2"<< endl;
gro<< " 3- this is line 3 i guess..."<< endl;
gro<< " 4- tomatoe tomahtoe"<< endl;
gro<< ""<< endl;
gro<< ""<< endl;
gro<< "_________________________________________"<< endl;
gro.close();
}
else
{
gro.close();
}
ifstream vc; //we will open the file and get each line as a vector
vc.open("groceries.txt", ios::in);
if (vc.is_open())
{
while(vc.good())
{
getline(vc, txt);
lines.push_back(txt);
}
}
system("CLS");
cout<< "Which line do you want to see?"<< endl;
cout<< ""<< endl;
cin>> lin;
txt = lines[lin];
cout<< txt<< endl;
cout<< ""<< endl;
system("PAUSE");
return 0;
}
int main()
{
char ch;
int x;
x = 0;
while (x == 0)
{
cout<< " MENU"<< endl;
cout<< ""<< endl;
cout<< ""<< endl;
cout<< " 1- display a file"<< endl;
cout<< " 2- quit"<< endl;
cout<< "___________________________________________________"<< endl;
ch = _getch();
ch = toupper( ch );
if (ch == '1')
{
Sleep(10);
while(_kbhit()) _getch();
opnfile();
continue;
}
if (ch == '2')
{
Sleep(10);
while(_kbhit()) _getch();
return 0;
}
}
}
|
i dont know whats wrong...