A
arnuld
This is the partial-program i wrote, as usual, i ran into problems
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.
next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
{
ifstream infile;
infile.open("my_file");
/* Process File
Here
*/
}
int main()
{
std::vector<std::string> svec;
std::vector<std::string>* psvec;
std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;
std::cin >> p_my_file;
read_file( p_my_file, psvec );
return 0;
}
-------- OUTPUT --------------
[arnuld@Arch64 c++]$ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp:22: error: variable or field ‘read_file’ declared void
ex_08-09.cpp:22: error: ‘ifstream’ was not declared in this scope
ex_08-09.cpp:22: error: ‘my_file’ was not declared in this scope
ex_08-09.cpp:22: error: expected primary-expression before ‘*’ token
ex_08-09.cpp:22: error: 'svec' was not declared in this scope
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:39: error: 'ifstream' was not declared in this scope
ex_08-09.cpp:39: error: expected `;' before ‘my_file’
ex_08-09.cpp:40: error: 'p_my_file' was not declared in this scope
ex_08-09.cpp:44: error: 'read_file' was not declared in this scope
[arnuld@Arch64 c++]$
Opening the file is the 1st stage of the problem. 2nd stage will include
copying the each line as a library string into the vector. I am facing
problems at very 1st stage.
halfway:
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a function to open a file for input and then read its
coontents into a vector of strings, storinig each line as separate
element in vector.
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
/* using Pointers because 1st argument is an input file-stream and
for 2nd argument i want to take the original vector, not the copied
one.
next line is the source of error, line #22 */
void read_file( ifstream* my_file, std::vector<std::string>* svec )
{
ifstream infile;
infile.open("my_file");
/* Process File
Here
*/
}
int main()
{
std::vector<std::string> svec;
std::vector<std::string>* psvec;
std::cout << "Enter the full Path to file: "; ifstream my_file;
ifstream* p_my_file;
std::cin >> p_my_file;
read_file( p_my_file, psvec );
return 0;
}
-------- OUTPUT --------------
[arnuld@Arch64 c++]$ g++ -ansi -pedantic -Wall -Wextra ex_08-09.cpp
ex_08-09.cpp:22: error: variable or field ‘read_file’ declared void
ex_08-09.cpp:22: error: ‘ifstream’ was not declared in this scope
ex_08-09.cpp:22: error: ‘my_file’ was not declared in this scope
ex_08-09.cpp:22: error: expected primary-expression before ‘*’ token
ex_08-09.cpp:22: error: 'svec' was not declared in this scope
ex_08-09.cpp: In function 'int main()':
ex_08-09.cpp:39: error: 'ifstream' was not declared in this scope
ex_08-09.cpp:39: error: expected `;' before ‘my_file’
ex_08-09.cpp:40: error: 'p_my_file' was not declared in this scope
ex_08-09.cpp:44: error: 'read_file' was not declared in this scope
[arnuld@Arch64 c++]$
Opening the file is the 1st stage of the problem. 2nd stage will include
copying the each line as a library string into the vector. I am facing
problems at very 1st stage.