Cannot print string with std::end [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am having trouble with printing a string in C++.
I know there are lots of topics about this matter on SO, but most say to include <string>, <iostream> or namespace std. But I did all of that but still encounter the issue. Here is my code and the error.
#include <iostream>
#include <string>
using namespace std;
//...
void affiche_date(int annee, int nbjours) {
string mois;
if (nbjours>31) {
mois = "avril";
nbjours -= 31;
} else {
mois = "avril";
}
cout << "Date de Paques en " << annee << " : " << nbjours << " " << mois << end;
}
int main() {
int annee ( demander_annee() ) ;
int jour ( date_paques(annee) );
affiche_date(annee, jour);
}
Here is the error I get when I compile:
"error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘<unresolved overloaded function type>’)"
This error is coming from the line with the cout in the function I gave you.
I am using Geany on linux Ubuntu and using c++11.
Thanks for you help

std::end() is a function for getting an iterator to the end of a container.
You meant to use the std::endl stream manipulator instead.
Note: avoid using namespace std; in your actual code, either take advantage of using directives to bring in only what you need, or favor qualifying names with their namespaces, like I have here.

Related

Getting input in a String in cpp [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
Hello I want to get some input in a string in cpp and I am getting and error. Here is the code:
#include <iostream>
int main() {
using namespace std;
string name;
cout << "Type your name:";
cin >> name;
cout << "Your name is: " << name;
return 0;
}
I am building the project and I get this error:
Test1.cpp:10:6: error: invalid operands to binary expression
It is this line: cout << "Type your name:";
What am I missing here ? It is the first time when I am using c++
You need to include header <string>
#include <string>
<iostream> does not include <string>. Hence, you also need to include <string> in order to use std::string.
#include <iostream> // for std::cout, std::cin
#include <string> // for std::string

C plus plus expected unqualified id [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
On line five of my code, the compiler raises an error. "error: expected unqualified-id
std::string send(message); {"
What error is this? How do I fix it?
Here's my code:
#include <iostream>
#include <fstream>
std::string message = "blank";
std::string send(message); { // here it raises the error
std::ofstream MyFile("messagepy.txt");
std::ofstream MyFile; << "Files can be tricky, but it is fun enough!";
}
// // // // // // // // // // // // // //
int main() {
std::cout << "defining is done.";
}
You have some syntax errors in there. Not sure what your code is meant to do, but here is my guess:
#include <iostream>
#include <fstream>
#include <string>
void send(std::string message)
{
std::ofstream MyFile("messagepy.txt");
MyFile << message;
MyFile << "Files can be tricky, but it is fun enough!";
}
int main()
{
std::string message = "blank";
send(message);
std::cout << "defining is done." << std::endl;
}
I believe the error is caused because you didn't #include <string>.
But there are other problems too. It sort of looks like you meant to create a send function but the semicolon ; is causing it to look like a declaration of a global variable send constructed with message, and then a code block which is a syntax error because it isn't part of a function.

c++ : invalid operands to binary expression [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I don't know what's wrong here ?
It's just running errors !!!
#include <iostream>
using namespace std;
int main()
{
cout << string("hello world");
return 0;
}
Read more about C++. So read first Programming -- Principles and Practice Using C++.
Then read C++ reference documentation, notably the one about std::string-s.
You need to #include <string>
You should enable all warnings when compiling. If using GCC, compile with g++ -Wall -g
You don't need that string before the actual string:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
return 0;
}
Or, alternatively, if you're trying to store a string:
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str = "hello world";
cout << str;
return 0;
}

"{" missing function header (old style format list) - expected a declaration [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm really really new to C++ and this is my first program on Visual Studio 2015, It shows me 2 errors:
"{" missing function header (old style format list)
expected a declaration
#include "stdafx.h"
#include <iostream>
int main();
{
cout << "Hello World";
return 0;
}
int main() remove ; at the end.
#include "stdafx.h"
#include <iostream>
int main(); // this ';' is giving problem remove it.
{
std::cout << "Hello World"; // use std::cout
return 0;
}

main.cpp|45|error: expected primary-expression before "int" and "double" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
File sys.cpp:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <fstream>
using namespace std;
[...]
struct kmph_in_mps
{
int kmph[4];
int result[4];
void kmph_erfassen()
{
for (size_t i = 0; i < 4; ++i)
{
cin >> kmph[i];
}
}
void mps_erfassen(int kmph, double result)
{
result = kmph / 3.6;
}
void ergebniss_ausgeben()
{
cout << endl << kmph << "Km/h sind " <<result << " Meter pro Sekunde\n";
}
};
[...]
File main.cpp:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "sys.cpp"
#include <fstream>
kmph_in_mps c;
[...]
void Kmph_in_mps()
{
system("cls");
cout << "\nKm/h: ";
c.kmph_erfassen();
c.mps_erfassen(int kmph, double result);
c.ergebniss_ausgeben();
t.beenden();
}
[...]
Errors:
Error: expected primary-expression before “int”
Error: expected primary-expression before “double”
I am a learning C++, and I dont get what to do now.
I am searching for answers at the internet and here, but I dont realy find the right one.
Which primary expression do I have to write before "in" and "double"?
Or am I doing everything completly wrong, like a beinner does? :P
Edits:
I tryed return result, but it seems to be not allowed in a void.
I already tryed c.mps_erfassen(); but it is gives me an error, too: error: no matching function for call to `kmph_in_mps::mps_erfassen()'|
I already tryed c.mps_erfassen(kmph, result); but then I do not declare them both in this scope. They are declared in the other file (sys.cpp). :S
c.mps_erfassen(int kmph, double result);
//^^^remove int and double
When you call a function, you should not put the type before the parameters.
This
c.mps_erfassen(int kmph, double result);
should be
c.mps_erfassen(kmph, result);
Let function deduce the type :)
EDITED IN RESPONSE TO COMMENT:-
You are creating object of struct in main.cpp while it's definition is in sys.cpp. How would main.cpp would get to know what your struct means.
For better design, place declaration of struct in header file say sys.h, then define required members in .cpp file say sys.cpp ( you have to include sys.h ). And then use that struct in your main.cpp ( again you have to include sys.h over here ).