File editing help!

Pages: 123
Is C++17 better, or what???
OK so, um, I don't have a C++17 compiler, but I used an online one and it worked with your code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>

auto streambuf_contents(std::istream& stream)
{
	return std::string(std::istreambuf_iterator{stream}, {});
}

int main()
{
	std::ifstream fin("in", std::ios::binary);
	std::string bytes = streambuf_contents(fin);
}


Any C++ IDE you know of?
OK so, um, I don't have a C++17 compiler, but I used an online one and it worked with your code:

You'll benefit from updating, but you don't need to. Change the word auto to std::string and the resulting code will be compatible.

A good online compiler is Matt Godbolt's Compiler Explorer:
https://godbolt.org/
Coliru is also useful because it allows shell access:
http://coliru.stacked-crooked.com/

Any C++ IDE you know of?

You don't need to replace your IDE, but just the compiler. Still, if you want, you can get an up-to-date IDE + compiler from
https://visualstudio.microsoft.com/vs/features/cplusplus/

Somewhere there is an option to only install the build tools, if you don't want to get the whole thing. Also make sure to install Clang, another compiler:
https://devblogs.microsoft.com/cppblog/clang-llvm-support-in-visual-studio/#getting-clang-on-windows

There are substantial advantages to using multiple compilers. One compiler may catch errors the other misses, or give clearer diagnostics in some cases. You'll make better software if you use both.

The code will not compile. even with auto changed.
Last edited on
For an on-line compiler, have a look at repl.it https://repl.it/

What os/compiler are you using?

What error messages are you getting?
Last edited on
The code will not compile. even with auto changed.


Oh, sorry. You have to say
1
2
3
4
std::string streambuf_contents(std::istream& stream)
{
	return std::string(std::istreambuf_iterator<char>{stream}, {});
}

instead.
I'll try that.

EDIT: I get a few warnings about C++11 only, but it seems to work fine. Thanks!

I think the warnings are because my IDE, Dev-Cpp is outdated.
Last edited on
What os/compiler are you using?


I'm using Dev-Cpp IDE, Windows.

The errors cleared up and I just got some warnings.
I just did a std::cout << bytes.size();

and it said 7216....

Finding an offset in there will not be easy.

EDIT: I used HxD hex editor and it made it really easy! :D
Last edited on
Dev-C++. That is a joke. An 5 year+ old outdated joke if you are using the Orwell fork. Even worse if you are using the original Bloodshed Dev-C++.

I think the warnings are because me IDE, Dev-Cpp is outdated.

You got that right.

You'd be better off IMO using Code::Blocks. Still free with a newer IDE and compiler underneath.
http://www.codeblocks.org/

Orwell's Dev-C++ is from 27 April 2015, with TDM-GCC 4.9.2 as the compiler. No C++17, no C++20 when it is officially released. That seriously limits your usage for modern C++. The current official release of TDM-GCC that I can easily find is 9.2.0.

C::B makes it easy to change the underlying compiler if you don't like the supplied MinGW-W64. Updating the compiler is also easy when new versions are released, so you can stay up-to-date being able to use new C++ features as they are released.

With Windows there is a decent alternative, Visual Studio. The Community edition is free. Since VS is MS it makes creating Windows apps less bulky compared to Dev-C++ or C::B. VS is rather bulky itself, 10-20 GBs depending on what what packages you select to install, but it has good tools for debugging, app templates for console or GUI app, etc. You can even do command-line compiling with VS.

One thing to note: C++ is NOT installed as a default package. You have to manually select it.

VS is constantly being updated, more often than C::B.

I personally have installed and use C::B 2004 and VS Comm 2019. Different compiler implementations can have different "quirks," so having at least two compilers to use makes testing code easier to produce generic code.

Installing and using a new compiler/IDE can be intimidating. The Learn C++ site has you covered with some lessons on the basics of installing and using both C::B and VS.

I suggest you read ALL of Learn C++'s chapter 0 lessons:
https://www.learncpp.com/cpp-tutorial/introduction-to-these-tutorials/

Poking around ALL of the lessons wouldn't hurt, you'd learn a lot. Books are nice, but once they are published they aren't updated. Learn C++ is.

Learning how to compile/debug on the command-line is useful, very useful. Allows the programmer greater flexibility. IDEs are useful tools for beginners, but they can be a crutch.

Command-line compilation/debugging is not something I usually do, but I am taking some time to learn. It is real slow going.
I have Code::Blocks, but I couldn't figure out how to compile.
I also use Visual Studio 2019. When I don't mind waiting for it to slowly start up...
I think the warnings are because me IDE


I meant my IDE.

I kinda hate Visual Studio 2019, only because I can not figure out how to
compile a single .cpp file without making a project first...

Does anyone know how?

Someone here had a batch file, but I couldn't seem to make it work.
I kinda hate Visual Studio 2019, only because I can not figure out how to
compile a single .cpp file without making a project first


I have Code::Blocks, but I couldn't figure out how to compile

You have to do the same thing, create a project, with Dev-C++. It is the nature of the beast with IDEs (Integrated Development Environment). VS and C::B simply do the grunt work differently.

How to compile a console program in VS and C::B, as well as doing command-line compiling:
https://www.learncpp.com/cpp-tutorial/writing-your-first-program/

Someone here had a batch file, but I couldn't seem to make it work.

Stop trying to do something experts do as a matter of course, learn the basics first. You will only get frustrated if you continue.

Take time to do the introduction lessons (and more) at Learn C++. It will be time well spent. Right now you are fighting the tools. Don't.
No, Dev-Cpp allows compiling of a single source file without making a project.

In Visual Studio 2019, the Build button dissapears unless you have a project open.
Compiling without a project doesn't produce an executable. Especially useless when the compilation is not useful for the current standard.

I've used Dev-C++ and found it to be an old piece of horse droppings. Continuing to use it is doing you zero favors.

You concentrate on trivial BS and ignore the advice of people who know what the hell they are talking about.
No need to get mad about it, just give a direct answer as to how to compile one .cpp file,
sometimes it's needed, MOST TIMES!

If you must use a single file either learn to compile the code at the command line, or make one "default" project and reuse it to make different programs. Projects are the key to both Visual Studio and Code Blocks. They allow you to easily set many different parameters, such as warning levels, standard used, and many other features that you "should" be using for every project.

No need to get mad about it

I'm not mad, that interpretation is on you.

sometimes it's needed, MOST TIMES!

I can compile a single source file easily, using a project in VS, C::B or DC++. I do it all the time.

Use command-line compiling, so you don't need the overhead of the IDE setting the various switches needed to produce an executable. You will discover you more often than not still need to set switches to achieve the results you want.

Make files. The way to compile at the command-line and still set switches you use/need.
for single file compiles I don't use the IDE at all, just call g++ directly, which is literally g++ filename if you don't care too much about it. If you want the whole 9 yards you can add the warnings and set the language to c++ 17 or 20 and optimize etc flags to it.

that makes MY Batch file this one line:
g++ %1 -Wall -Wextra -pedantic -std=c++17
where %1 is the cpp file, eg for file compile.bat:
compile x.cpp

make files are a pain to me, I will go to the IDE project if I need that much.
Last edited on
Pages: 123