c++ vs2003 setting up a function that handles strings in the passing parameter

this should be an easy answer for you
i have inserted the below class ... CSaveProgflow in it is one function unpopulated working on just the string set up in the function.
if i have in the h and the cpp file  void savedatafile();  it works fine
but if i have i the file void savedatafile(string data);  with the inclusion of "string data "  as  the passing variable
it throws uo
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.h(12) : error C2061: syntax error : identifier 'string'
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(12) : error C2065: 'string' : undeclared identifier
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(12) : error C2146: syntax error : missing ')' before identifier 'data'
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(12) : error C2182: 'savedatafile' : illegal use of type 'void'
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(12) : error C2059: syntax error : ')'
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(13) : error C2143: syntax error : missing ';' before '{'
c:\c++ tree view\new files\TreeListV7v3\SaveProgflow.cpp(13) : error C2447: '{' : missing function header (old-style formal list?)

so what am i doing wrong please have been troling the net trying to figure it out but still not runnign am using VS2003
thanks for the help

....header
#pragma once
#include      "StdAfx.h"
#include <string>
#include <iostream>


class CSaveProgflow
{
public:
      CSaveProgflow(void);
      ~CSaveProgflow(void);
      void savedatafile(string data);
};

.........ccp
#include "stdafx.h"
#include ".\saveprogflow.h"

CSaveProgflow::CSaveProgflow(void)
{
}

CSaveProgflow::~CSaveProgflow(void)
{
}

void savedatafile(string data)
{

}
sydneyguyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sydneyguyAuthor Commented:
got it to compile using
using std::string;
before the class but why  does this work

also when i let vs2003 ad the class for me it actually puts in
#include ".\saveprogflow.h"   why is this so  the .\ i am asking about
AndyAinscowFreelance programmer / ConsultantCommented:
Does this cure it - I've reorganised the #includes

....header
#pragma once


class CSaveProgflow
{
public:
      CSaveProgflow(void);
      ~CSaveProgflow(void);
      void savedatafile(string data);
};

.........ccp
#include      "StdAfx.h"
#include <string>
#include <iostream>
#include ".\saveprogflow.h"

CSaveProgflow::CSaveProgflow(void)
{
}

CSaveProgflow::~CSaveProgflow(void)
{
}

void savedatafile(string data)
{

} 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sydneyguyAuthor Commented:
yes i does fix that problem but

#pragma once
#include      "StdAfx.h"
#include <string>
#include <iostream>

using std::string;

if include string is already defined in h why do i need to do it again by using std::string;  this i do not understand
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Karrtik IyerSoftware ArchitectCommented:
Include string, includes the header file during compilation, however c++ has a  concept of namespaces.
And string class is in std name space, so to use string class either everywhere do std::string, or at one place by saying using std::string.
Karrtik IyerSoftware ArchitectCommented:
More about namespaces, namespace(declarative region)  is a mechanism provided to organise and logically group the c++ code to avoid name collisions. So in this case you could easily have another string class in another library either in global namespace or some other namespace. Namespaces are not mandatory so by default all the classes, functions and variables are added to global namespace.
For More information you can refer link below :
https://googleweblight.com/?lite_url=https://msdn.microsoft.com/en-us/library/5cb46ksf.aspx&ei=GbCrCKPD&lc=en-IN&s=1&m=497&ts=1447769749&sig=ALL1Aj4vkx_J28qZjh6z5CySnsGBHnJGTw
sarabandeCommented:
using std::string;
before the class but why  does this work

without a using clause 'using std::string;' or 'using namespace std;' the type 'string is unknown. you would have to use std::string for all occurrences instead.

Sara
sarabandeCommented:
sorry for the replication. i thought i had refreshed the thread ...

if include string is already defined in h why do i need to do it again by using std::string;

that is not the same. if you open the header <string> you will see that string actually was typedef'd from basic_string<char> and that class basic_string is below namespace std. a namespace actually makes it necessary to add it by scope as a prefix to class type. so std::string or std::basic_string<char> actually is a must when no using clause is given.

note, in header files it is recommended to use the std:: prefix and not work with using clause. that is to avoid problems with older header files (c headers) which may use 'string' as a variable name. such kind of ambiguity gives very strange errors and should be avoided.

Sara
Karrtik IyerSoftware ArchitectCommented:
#include ".\saveprogflow.h"   why is this so  the .\ i am asking about
For the above question :
You could have your header files in different directories.
Assume your project folder structure in windows Explorer is say
Myproject (folder)
-->common (folder)
----->common.h
-->utility (folder)
-----> utility.h

Say in utility.h you want to include common.h
You can say either write below code in utility.h
#include ..\common\common.h
This is a way to specify relative path.
First ".."  takes you to MyProject folder.
And next common takes you to common folder and then includes common.h.
Another way to do it is in the project include path(project properties) explicitly specify the folder MyProject\Common. In that case following code shall work
#include common.h
Or another way is to have the code in common.h in a namespace by name common. And by default the compiler looks for files directly inside the  MyProject folder (since it is part of default include path), then following code shall also work.
#include <common\common.h >
I prefer the last approach since I don't need to provide relative paths which may not a portable syntax (..\ syntax) across compilers. Also I don't need to provide any additional include paths since by default MyProject directory is already included.
Basically if you all your files in a flat structure inside same folder than you don't need the relative path syntax.
Hope this helps.
sydneyguyAuthor Commented:
thanks for all your help bit of every thing out of the above to get it going so thanks for your time
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.