1

In one of my modules, I have a function (changeNum) that returns a string and accepts a parameter that is a string. I tried to declare this function in my header file as following:

std::string changeNum(std::string s); 

[and I included the string header file into the header file as well]

but I'm still getting the following error in my header file: "unknown type name 'string'" What do I do?

Here is the whole code: My header file is the following:

#pragma once
#include <string>
std::string changeNum(std::string s); 

My module with the function changeNum is defined as the following

#include <string>
string changeNum(string s){
    return s;
}

1 Answers1

0

Try it:

Header.h

#pragma once
#include <string>

std::string changeNum(std::string s);

Source.cpp

#include "Header.h"

std::string changeNum(std::string s) {
    return s;
}

main.cpp

#include "Header.h"
#include <iostream>

int main()
{
    std::string sample_str = changeNum("Hello");
    std::cout << sample_str.c_str();
}

Tested on VS and removed #include "pch.h" from aforementioned code.

7eRoM
  • 443
  • 4
  • 14