Hello, I am new to C++, I just started yesterday. I am trying to make a fuction where I can return a line from a .txt with linesi(file.txt,line number).
But I get the following errors, and being new, I have no idea why:
C:\Documents and Settings\Family\Desktop\Untitled21.cpp In function `int main()':
17 C:\Documents and Settings\Family\Desktop\Untitled21.cpp invalid conversion from `char*' to `char'
17 C:\Documents and Settings\Family\Desktop\Untitled21.cpp initializing argument 1 of `int linesi(char, int)'
C:\Documents and Settings\Family\Desktop\Untitled21.cpp In function `int linesi(char, int)':
22 C:\Documents and Settings\Family\Desktop\Untitled21.cpp invalid conversion from `char' to `const char*'
22 C:\Documents and Settings\Family\Desktop\Untitled21.cpp initializing argument 1 of `std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]'
28 C:\Documents and Settings\Family\Desktop\Untitled21.cpp invalid conversion from `char*' to `int' 24 C:\Documents and Settings\Family\Desktop\Untitled21.cpp [Warning] address of local variable `buffer2' returned
Just wish I knew what I was doing wrong. Here is my code:
I've been working on this for hours.. help would be greatly appreciated.Code:#include <iostream> #include <fstream> using namespace std; int linesi (char b, int c); int main () { char b[256]; int c; char buffer[256]; cout << "Please enter the filename of a .txt file: "; cin >> b; cout << "Please enter the line number: "; cin >> c; ofstream lfo("list2.txt"); lfo << linesi(b,c); } int linesi (char b, int c) { ifstream ag(b); int x = 1; char buffer2[256]; while (!ag.eof()) { ag.getline(buffer2, 200); if (x == c) { return buffer2; } x++; } }



LinkBack URL
About LinkBacks


