You can also try like below,
cout << " Reading from txt file" << endl;
ifstream file("file.txt");
string content;
int i = 0;
while (file >> content) {
cout << content << ' ';
i++;
if (i == 2)
{cout<<endl;i=0;}
}
system("pause");
return 0;
More Related Contents:
- When should you use ‘friend’ in C++?
- Is std::unique_ptr required to know the full definition of T?
- How to use the PI constant in C++
- Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviations with _mm_popcnt_u64 on Intel CPUs
- C++ obtaining milliseconds time on Linux — clock() doesn’t seem to work properly
- What are the different calling conventions in C/C++ and what do each mean?
- initialize a const array in a class initializer in C++
- What is Objective C++? [closed]
- How to read a binary file into a vector of unsigned chars
- OpenGL – mask with multiple textures
- Conversion from string literal to char* is deprecated
- Should I learn C before learning C++? [closed]
- Escaping a # symbol in a #define macro?
- How to create a shared library with cmake?
- Identifier not found error on function call
- std::to_string – more than instance of overloaded function matches the argument list
- Force all classes to implement / override a ‘pure virtual’ method in multi-level inheritance hierarchy
- C++ pointer multi-inheritance fun
- Complex C declaration
- How do traits classes work and what do they do?
- Is a wide character string literal starting with L like L”Hello World” guaranteed to be encoded in Unicode?
- C++11 “overloaded lambda” with variadic template and variable capture
- Why can I call base template class method from derived class
- What is a good random number generator for a game?
- Does throw inside a catch ellipsis (…) rethrow the original error in C++?
- How to avoid errors while using CRTP?
- Alpha rendering difference between OpenGL and WebGL
- C++ Extract number from the middle of a string
- Getting another process command line in Windows
- Private constructor and make_shared