strlen() problem

Hi all,
I am having trouble getting this simple program going.
#include <iostream>
#include <string.h>
#include <fstream.h>

void main()
fstream f;
char c;"f:\\test.txt",ios::in);


I keep getting an error ;
error C2664: 'strlen' :cannot convert parameter 1 from 'char' to 'const char*'

Its reading from the file no problem, but i cant get the string length to work, I would be grateful for any help with.
Thanks in advance.
there is no fstream.h, change it to <fstream>

also the namespace std is missing
Variable c is a single character. You don't need to calculate its length.
@ Darkmaster
When i don't put the .h after fstream I get an error;
error C2065 'fstream' : undeclared identifier

when I add the " using namespace std" I get an error;

error C2871: 'std' : does not exist or is not a namespace

Im using Microsoft Visual C++ 6.0 fwiw
Last edited on
@ Chervil

I Have a project for my c++ class where i need to be able to read the contents of a file and set up a dynamic array the size of that string. The above code is just me trying this strlen() out. Should I use an array?
Not sure which string you mean.
You mean you want to know the size of the file? Or just the size of the first line? or the first word?

See example code here for file length.
I am doing a cash register project, selling 3 items. I save the number in stock of all 3 items to a file as well as the total sales. all 4 are of float type.
An example of the text file looks like this when opened:


I need to read these 4 values in and set up a dynamic array for them.
You're on the wrong way. You don't even need to use strlen I guess.
Also you need to include vector. Enough said I hope? No? std::vector<int>.
I have the program working fully without using the dynamic array, Its part of the assignment tough to read in from the file and set up a dynamic array for the size if what's in the file. I am very new to C++ , so I am not sure what you mean when you mention vector.
@ electronicstudent: update your tools to:

Visual Studio 2008 Express:

Or Visual Studio 2010 Express:

Or at least make sure you use the latest Visual Studio 6.0 service pack:
Ah, so the 'length' you are after is a count of how many lines the file contains.
Indeed, the use of a vector (which is basically an array which can dynamically resize itself as required) sounds like the answer.
Topic archived. No new replies allowed.