Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
it's a problem with my string defining
i implement a class below:

myfile.h:
C++
#pragma once
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <string>
#include <conio.h>
#include <fstream>

class myfile
{
public:
//...
/* * */ void print(string s);
};


myfile.cpp:
C++
#include "stdafx.h"
#include "myfile.h"
#include <string.h>
#include <string>
#include <conio.h>
#include <iostream>
/* * */void myfile::print(string s){
	std::cout<<"string is: "<<s;
}


*- Why does it say undeclared identifier string?
Am i missing something?
How can i fix it?
Posted
Updated 1-Aug-14 21:46pm
v2

1. It is a directive for avoiding the problem of multiple inclusion of header files, see: pragma once at MSDN[^].

2. Because you forgot to qualify string with std, namely you have to use std::string (or add the using std; statement).
 
Share this answer
 
Comments
m.r.m.40 2-Aug-14 3:56am    
Thank you,
CPallini 2-Aug-14 4:07am    
You are welcome.
m.r.m.40 2-Aug-14 15:52pm    
Hi again,
a question:
now my first educational program which i was working on is done.
but i have problems with it, like " I don't know if it's working correctly or not? or is it working the way it is supposed to? ".
should i post my program and its results as an article here?
how can i do that? i mean ask others opinions about that.
CPallini 3-Aug-14 4:53am    
The corect behaviour of a program can be asserted matching its output with the expected one. If you have any doubt, then, yes, you might post the code and describe its expected output here.
hi,

place the following line in your myfile.h file before class definition.

using namespace std;
 
Share this answer
 
Comments
m.r.m.40 2-Aug-14 6:34am    
Thank you,
hi,
#pragma should not be a reason to worry #pragma once specifies that the file will be included only once by the compiler when compiling a source code file. This can reduce build times. It has its own wiki page if you cared to google it.[^]
Compiler does not know what is 'string'. Either make it std::string OR after the #includes put a using namespace std;

These are not very difficult questions to find answers to on your own. Please google them bfore posting here.

hope it helps!
 
Share this answer
 
Comments
m.r.m.40 2-Aug-14 6:33am    
Actually, if you see the question, you'll see that I've improved the question by removing pragma part. meaning i figured that out before getting answer.
usually i use namespace std for my input and output and i didn't know that string is from std while i was using std, that's why i asked this question,I wasn't being lazy I just thought there might be a problem with my class definition.
BTW,
Thanks for your hint,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900