Error when using conio.h to change text colour - c++

Hey just found a library i want to use called coni.h to change text colour. But im getting an error in one of the functions: textcolour(RED); It says that it is undefined.
#include <iostream>
#include <string>
#include <conio.h>
#include "Storyline.h"
using namespace std;
int main()
{
Storyline story;
story.Story("Title.txt");
textcolor(MAGENTA+BLINK);
cout << "Hello";
getchar();
getchar();
}

I simply used system("color 0a"); from the "Windows.h". And i now have what i needed.

Related

All strings are unidentified

#include <iostream>
#include <time.h>
#include <string.h>
#include <stdio.h>
int main()
{
string msg;
printf("Enter the message that you wish to display as scroller: ");
getline(cin,msg);
msg=msg+". ";
int x=0;
while(1)
{
Scroll(msg);
wait(100);
system("cls");
x++;
}
cin.get();
return 0;
}
I Have this C code and all strings in the file say 'identifier "string" is undefined'. I tried including <string> instead of <string.h> but it didn't work. Why is it not working?
Add
using namespace std;
After includes (but before main). Or, better, use notion of:
std::string // instead of string
Update: I missed the point of this being C-question. I will leave this answer, but for the sake of formality, use it if you came from Google and you are working with C++.
This is C++ code, not C.
The compiler is probably getting confused because it cannot parse it, so then it finds C-like code and all identifiers do not exist.
The includes should be:
#include <iostream>
#include <ctime>
#include <string>
#include <cstdio>
You are also missing a:
using namespace std;
Plus the definitions for Scroll and wait etc.

Where to get _fileno and _O_U16TEXT?

I'm trying to print the text "Ääkkösiä ruutuun." to console with c++. I have windows 7 and am using Code::Blocks editor. Searching on the subject I found that maybe these sort of lines would help
_setmode(_fileno(stdout), _O_U16TEXT);
wstring s{L"Ääkkösiä ruutuun."};
wcout<<s<<endl;
But when I try to compile it, I get the error: _fileno was not declared in this scope.
I have all these includes:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdexcept>
#include <cmath>
#include <sstream>
#include <fstream>
#include <codecvt>
#include <locale>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <cstdio>
#include <ostream>
what am I missing?
Also, one other thing I tried was locale, but then locale::empty wasn't found! Why doesn't my c++ have anything in it?
EDIT
Here is a picture of what my program is doing now.
It prints out just the first letter (Ä). What happens to the rest?
Ok, it seems that setmode sets it so that only one letter gets printed. (Even trying to print normal texts with multiple commands, just results in a single letter.) Without it the scandinavian letters don't print correctly, thought. They look like this:
The answer you found is for Visual Studio, not Code::Blocks.
While the C standard specifies what should in in <stdio.h>, it only specifies a minimum. Implementors may add their own functions, and should do so using an _ (underscore prefix). This is why you should NOT use that prefix. You don't know what you'll break. Microsoft clearly signaled their non-standard extensions using the correct prefix.
The answer is tagged C++, but C++ inherits the contents of <stdio.h> from C.
The line
setlocale(LC_CTYPE, ".OCP");
works!
A complete example:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
wstring readFile(const char* filename) {
wifstream wif(filename);
locale myLoc("");
//locale utf8_locale(locale(), new gel::stdx::utf8cvt<true>);
wif.imbue(myLoc);
basic_stringstream<wchar_t> wss;
wss << wif.rdbuf();
return wss.str();
}
int main() {
setlocale(LC_CTYPE, ".OCP");
wstring contents = readFile("test.txt");
wcout<<L"Does anything get printed out at all???"<<endl;
//wcout <<contents<<endl;
wstring s{L"Ääkkösiä ruutuun."};
wcout<<s<<endl;
wcout<<L"Näkyykö äkköset?"<<endl;
return 0;
}
The text read from file (utf-8) still doesn't print correctly, though.
It should be
Hei!
Täällä on kaksi riviä.
ä's go awry there.
Output:

Program not executing after instanciating a class from imported library

I'm trying to use the library ZBar to read QRCode with c++. I am not an expert about this language. I have the following problem:
#include <iostream>
#include <zbar.h>
using namespace std;
using namespace zbar;
int main()
{
cout << "Hello World!" << endl;
//Image image;
return 0;
}
This code does actually print the "Hello World" as expected. But if I remove the comment, obtaining the following code:
#include <iostream>
#include <zbar.h>
using namespace std;
using namespace zbar;
int main()
{
cout << "Hello World!" << endl;
Image image;
return 0;
}
Everything is still compiled correctly, with no errors or warnings, but I don't obtain any output!! The program reaches the end without executing any instruction!
I just used this code to semplify, but the problem actually is that, as soon as I add an instruction using classes from zbar, it seems like I am "clearing" the main! How is it possible? What should I do? Thank you!

Why YouCompleteMe still show syntax warning when I include the correct C++ library?

When I include the required library, the "#include.." line doesn't show any warning. But when I use the functions in that library, I find the Vim shows that "..use of undeclared function...". It seems that the library is not correctly included. So I want to know how to figure out this problem?
The screenshots for this question are attached as follows:
Try including it as follows:
#include <stdlib.h> //use <> instead of ""
Also, the "printf" function comes from the "cstdio" library so try implementing that library as well,
#include <stdio.h>
UPDATED
The easiest way to fix that problem is;
Include the stdio.h library
#include <stdio.h>
Then, instead of typing;
printf('s');
you do,
printf("s");
Now, if you really want to print a character 's', then use,
printf("%c", 's'); // Tells the printf function that 's' is a character
The final code would look like;
#include <stdio.h>
int main(int argc, char** argv) {
printf("s");
printf("%c", 's');
return 0;
}
Now, your comment was that "cout" does not work. In order for "cout" to work you need to include the iostream library:
#include <iostream>
Then, you can use "cout" in your code;
std::cout << 's';
std::cout << "s";
Or you can include "namespace std" and the "iostream" library to avoid using std:: before "cout"
include <iostream>
using namespace std;
Thereafter, use cout without std::
cout << 's';
cout << "s";
The final code would be;
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << 's';
cout << "s";
return 0;
}
If you want to learn more about what is in the iostream library and how to use it I recommend using this site:
http://www.cplusplus.com/reference/iostream/
Also, for the stdio.h,
http://www.cplusplus.com/reference/cstdio/

Building in Visual Studio not recognizing getline() or stoi() even with #include <string> and <fstream> statements

I've been trying to learn C++ over the past couple of days, and ran into a problem when I was trying to use the getline() and stoi() methods in some practice code:
#include <string>
#include <fstream>
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
string numberGuessed;
int intNumberGuessed = 0;
do {
cout << "Guess a number between 1 and 10";
getline(cin, numberGuessed);
intNumberGuessed = (stoi(numberGuessed));
cout << intNumberGuessed << "\n";
} while (intNumberGuessed != 4);
cout << "You win\n";
return 0;
}`
When I tried to build this code in VS 2015, the console could not identify getline or stoi as if I hadn't added #include statements for string and fstream. Is there something wrong with my code or is it something to do with VS?
It's something to do with VS.
Since you have
#include "stdafx.h"
I'm guessing you have precompiled headers turned on, and "stdafx.h" is the precompiled header. (That's the default name in VS)
With precompiled headers turned on, anything before the include statement for the precompiled header is ignored.
Either make sure #include "stdafx.h" is the very first thing in the file (except for comments), or turn off precompiled headers.