Why does my program produce correct output when my vector< vector< vector<int> > > is larger than the
By : Chris
Date : March 29 2020, 07:55 AM
this one helps. Your application is able to allocate more memory than is physically installed on your computer because it supports virtual memory. Allocation, paging and releasing virtual memory is handled by the operating system to allow your application to run without having to worry about exhausting physical memory. Keep in mind that releasing the allocated memory may not occur immediately when your application frees memory from it's heap. This has a tendency to make people think their application is at times using more memory that it should.
|
My functions for a vector don't seem to be working? C++ (adding or deleting an item, displaying a vector)
By : Thunaer
Date : March 29 2020, 07:55 AM
hop of those help? Main problem: You are passing faveGames by value. Any changes to faveGames don't change the variable in main. code :
void addGame(vector<string>& faveGames);
void removeGame(vector<string>& faveGames);
int main(array<System::String ^> ^args)
faveGames.erase(deletedGameIter);
for(deletedGameIter = faveGames.begin();
deletedGameIter != faveGames.end();
++deletedGameIter) {
if(deletedGame == *deletedGameIter) {
faveGames.erase(deletedGameIter);
return
}
}
for(deletedGameIter = faveGames.begin();
deletedGameIter != faveGames.end(); ) {
if(deletedGame == *deletedGameIter) {
deletedGameIter = faveGames.erase(deletedGameIter);
}
else {
++deletedGameIter;
}
}
|
why vector begin() pointing to second element of vector and while displaying a all element vector after few pusback() ab
By : Risa Mardia Rahma
Date : March 29 2020, 07:55 AM
To fix this issue I am was just writing the small vector program in visual stdudio 2010. , Try This out you will get desired output It worked fine with g++4.2: code :
#include <iostream>
#include <vector>
using namespace std;
int main() {
using namespace std;
vector<int> myvector;
myvector.push_back(1);
myvector.push_back(2);
myvector.push_back(3);
myvector.push_back(4);
for( vector<int>::iterator i = myvector.begin(); i < myvector.end(); ++i)
{
cout<<*i<<endl;
}
//even check this second loop
for(int i=0;i<myvector.size();i++)
{
cout<<myvector.at(i)<<endl;
}
return 0;
}
|
Last item of vector not displaying/vector indexing issue
By : Mohsen
Date : March 29 2020, 07:55 AM
Hope that helps I have a weird bug that I simply cannot find. code :
Graph g(sizeof(_vertices));
Graph g(_vertices.size());
Graph g;
for i in {S,H,R,C,G}\ {S,H,R,C,G}; do valgrind ./test <<< $i; done
#include <boost/algorithm/string.hpp>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/properties.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/tokenizer.hpp>
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <utility>
#include <vector>
namespace {
typedef int Weight;
typedef boost::property<boost::vertex_name_t, std::string> VertexNameProperty;
typedef boost::property<boost::edge_weight_t, Weight> EdgeWeightProperty;
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, VertexNameProperty, EdgeWeightProperty> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
typedef boost::property_map<Graph, boost::vertex_name_t>::type NameMap;
typedef boost::iterator_property_map<Vertex*, IndexMap, Vertex, Vertex&> PredecessorMap;
typedef boost::iterator_property_map<Weight*, IndexMap, Weight, Weight&> DistanceMap;
}
template <typename V, typename VM>
Graph readGraph(std::string const& fname, V& _vertices, VM& vertex_map) {
std::ifstream input(fname);
std::string line, vertex;
std::getline(input, line);
assert(line == "Vertices:");
std::getline(input, line);
boost::char_separator<char> sep(",");
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
tokenizer tok(line, sep);
for (auto &i : tok) {
_vertices.insert(_vertices.end(), i);
}
Graph g;
for (auto &i : _vertices) {
vertex_map[i] = boost::add_vertex(std::string(i), g);
}
char c;
struct GraphParameters {
char source, target;
Weight weight;
};
std::getline(input, line);
assert(line == "Edges");
while (getline(input, line)) {
GraphParameters p;
std::istringstream iss(line);
if (iss >> c && c == '('
&& iss >> p.source >> c && c == ','
&& iss >> p.target >> c && c == ','
&& iss >> p.weight >> c && c == ')')
{
boost::add_edge(
vertex_map[std::string(1,p.source)],
vertex_map[std::string(1,p.target)],
p.weight,
g);
} else {
throw std::runtime_error("Parse error in '" + line + "'\n");
}
}
return g;
}
int main() {
std::vector<std::string> _vertices;
std::map<std::string, Vertex> vertex_map;
auto g = readGraph("input.txt", _vertices, vertex_map);
std::string start_vertex, end_vertex;
bool valid = false;
std::cout << "Vertices:" << std::endl;
for (auto &i : _vertices) {
std::cout << i << " ";
}
std::cout << std::endl;
while (!valid) {
std::cout << "Enter starting vertex: ";
std::cin >> start_vertex;
for (auto &i : _vertices) {
if (i == start_vertex) {
valid = true;
break;
}
}
}
while (valid) {
std::cout << "Enter ending vertex: ";
std::cin >> end_vertex;
for (auto &i : _vertices) {
if (i == end_vertex) {
valid = false;
break;
}
}
}
std::vector<Vertex> predecessors(boost::num_vertices(g));
std::vector<Weight> distances(boost::num_vertices(g));
IndexMap indexMap = boost::get(boost::vertex_index, g);
PredecessorMap predecessorMap(&predecessors[0], indexMap);
DistanceMap distanceMap(&distances[0], indexMap);
boost::dijkstra_shortest_paths(g, vertex_map[start_vertex],
boost::distance_map(distanceMap).predecessor_map(predecessorMap));
NameMap nameMap = boost::get(boost::vertex_name, g);
std::cout << std::endl;
typedef std::vector<Graph::edge_descriptor> PathType;
PathType path;
Vertex v = vertex_map[end_vertex];
for (Vertex u = predecessorMap[v]; u != v; v = u, u = predecessorMap[v]) {
std::pair<Graph::edge_descriptor, bool> edgePair = boost::edge(u, v, g);
Graph::edge_descriptor edge = edgePair.first;
path.push_back(edge);
}
std::cout << "Shortest path from " << start_vertex << " to " << end_vertex << std::endl;
for (PathType::reverse_iterator pathIterator = path.rbegin(); pathIterator != path.rend(); ++pathIterator) {
std::cout << nameMap[boost::source(*pathIterator, g)] << " -> " << nameMap[boost::target(*pathIterator, g)]
<< " = " << boost::get(boost::edge_weight, g, *pathIterator) << std::endl;
}
std::cout << std::endl;
std::cout << "Distance: " << distanceMap[vertex_map[end_vertex]] << std::endl;
std::cout << std::endl;
return EXIT_SUCCESS;
}
|
In foreach last value alone displaying in the output , other values are not displaying in the output?
By : Lazzaro The III
Date : March 29 2020, 07:55 AM
wish helps you Hello friend actually you cannot able to use table tag inside the tr tag and you are not declared the variable $report directly used in for-each statement. Try this code code :
$address_query = db_query('......');
$adddaterpt ='';
$report = '<table>';
foreach($address_query as $adds)
{
$adddaterpt .= $adds->date_reported;
$addrptdate = substr($adddaterpt, 0, 2) . "-" . substr($adddaterpt, 2, 2) . "-" . substr($adddaterpt, 4, 4);
$report.='<tbody id="address1">
<tr><td><b>ADDRESS:</b>' . $adds->addressline1 . $adds->addressline2 . $adds->addressline3 . $adds->addressline4 . $adds->addressline5 . $adds->state_name . $adds->pincode . '</td></tr>
<tr><td><b>CATEGORY:</b>' . $adds->addcategory_name . '</td>
<td><b>RESIDENCE CODE:</b>' . $adds->residence_name . '</td>
<td><b>DATE REPORTED:</b>' . $addrptdate . '</td>
</tr>
</tbody>';
}
$report.='</table>';
|